[all-commits] [llvm/llvm-project] 10c0ec: [clang][Lexer] Speed up HeaderSearch when there ar...

Troy Johnson via All-commits all-commits at lists.llvm.org
Tue Oct 18 08:21:53 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 10c0eca25523e3bf1872522bde4693aaa55513e0
      https://github.com/llvm/llvm-project/commit/10c0eca25523e3bf1872522bde4693aaa55513e0
  Author: Troy Johnson <troyj at meta.com>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M clang/include/clang/Lex/HeaderMap.h
    M clang/include/clang/Lex/HeaderSearch.h
    M clang/lib/Lex/HeaderSearch.cpp

  Log Message:
  -----------
  [clang][Lexer] Speed up HeaderSearch when there are many HeaderMaps

HeaderSearch already uses a caching system to avoid duplicate searches,
but the initial cold miss can take a long time if a build system has
supplied thousands of HeaderMaps. For this case, the SearchDirs vector
begins with those HeaderMaps, so a cache miss requires testing if the
sought filename is present in each of those maps. Instead, we can
consolidate the keys of those HeaderMaps into one StringMap and then
each cache miss can skip directly to the correct HeaderMap or continue
its search beyond the initial sequence of HeaderMaps. In testing on TUs
with ~15000 SearchDirs where the initial 99% are HeaderMaps, time spent
in Clang was reduced by 15%. This patch is expected to be neutral for
SearchDir vectors that do not begin with HeaderMaps.

Differential Revision: https://reviews.llvm.org/D135801




More information about the All-commits mailing list