diff options
author | Alexandre Ganea <37383324+aganea@users.noreply.github.com> | 2024-04-25 10:31:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-25 10:31:45 -0400 |
commit | 39ed3c68e51f1b04fe2890db9006ae1b176b1582 (patch) | |
tree | c0de7b611275aedb90f8de5df3dffa0025db60ed /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 76a3be7c766bd55221c3d0d0a74c42f82c5d76ed (diff) | |
download | llvm-39ed3c68e51f1b04fe2890db9006ae1b176b1582.zip llvm-39ed3c68e51f1b04fe2890db9006ae1b176b1582.tar.gz llvm-39ed3c68e51f1b04fe2890db9006ae1b176b1582.tar.bz2 |
[clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot code paths in `FileManager`. (#88427)
`FileManager::getDirectoryRef()` and `FileManager::getFileRef()` are hot code paths in `clang-scan-deps`. These functions are updating on every call a few atomics related to printing statistics, which causes contention on high core count machines.



After this patch we make the variables local to the `FileManager`.
In our test case, this saves about 49 sec over 1 min 47 sec of `clang-scan-deps` run time (1 min 47 sec before, 58 sec after). These figures are after applying my suggestion in https://github.com/llvm/llvm-project/pull/88152#issuecomment-2049803229, that is:
```
static bool shouldCacheStatFailures(StringRef Filename) {
return true;
}
```
Without the above, there's just too much OS noise from the high volume of `status()` calls with regular non-modules C++ code. Tested on Windows with clang-cl.
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 6e3baf8..66a45b8 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1293,6 +1293,10 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, diag::remark_module_build_done) << ModuleName; + // Propagate the statistics to the parent FileManager. + if (!FrontendOpts.ModulesShareFileManager) + ImportingInstance.getFileManager().AddStats(Instance.getFileManager()); + if (Crashed) { // Clear the ASTConsumer if it hasn't been already, in case it owns streams // that must be closed before clearing output files. |