[PATCH] D136019: [clang][lex] Avoid `DirectoryLookup` copies

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 18 17:49:42 PDT 2022


jansvoboda11 added a comment.

In D136019#3860557 <https://reviews.llvm.org/D136019#3860557>, @ributzka wrote:

> We could invoke clang with the `-stats` option and compare the result against the expected number of stat calls.

The `-stats-file=` option only tells you how many times Clang requested `DirectoryEntry` object from `FileManager` (i.e. calling `FileManager::getDirectory(StringRef)`). This function **only** touches the real file system once and caches information internally. Checking this doesn't really help us catch regressions like this one. It's a cheap operation and it's pretty common and reasonable for this number to change between commits.

What's actually expensive about this regression is calling `HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &)` multiple times, since `Dir.haveSearchedAllModuleMaps()` never changes (we only mutate the local `DirectoryLookup` copy). That function accesses the real filesystem via LLVM's VFS and **that** is actually the expensive operation:

  llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
  for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;
       Dir != DirEnd && !EC; Dir.increment(EC)) {
      //
  }

It would be nice to have statistics for these as well, but we don't have any infrastructure for that ATM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136019/new/

https://reviews.llvm.org/D136019



More information about the cfe-commits mailing list