This is an archive of the discontinued LLVM Phabricator instance.

[clang][deps] Only cache files with specific extension
ClosedPublic

Authored by jansvoboda11 on Mar 17 2023, 1:19 PM.

Details

Summary

In the scanner's VFS, we cache all files by default and only avoid caching stat failures for certain files. This tanks the performance of scanning with pre-populated module cache. When there is a stale PCM file, it gets cached by the scanner at the start and the rebuilt version never makes it through the VFS again. The TU invocation that rebuilds the PCM only sees the copy in its InMemoryModuleCache, which is invisible to other invocations. This means the PCM gets rebuilt for every TU given to the scanner.

This patch fixes the situation by flipping the default, only caching files that are known to be important, and letting everything else fall through to the underlying VFS.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Mar 17 2023, 1:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2023, 1:19 PM
Herald added a subscriber: ributzka. · View Herald Transcript
jansvoboda11 requested review of this revision.Mar 17 2023, 1:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2023, 1:19 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ributzka added inline comments.Mar 17 2023, 1:31 PM
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
160–161

s/Whitelist/Allowlist

Bigcheese accepted this revision.Mar 17 2023, 1:47 PM

This doesn't appear to behave as expected for PP_CacheFailure or PP_ScanFile without PP_CacheSuccess. Looks like that will still cache. Should probably just assert that's not the computed policy.

Looks good with those changes.

clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
160–161

I think we can just change this comment to something like:

Determine caching and scanning behavior based on file extension.

164–176

If you use LLVM_MARK_AS_BITMASK_ENUM I think you can remove these casts.

This revision is now accepted and ready to land.Mar 17 2023, 1:47 PM

Remove configurable CacheSuccess, rename CacheFailure to CacheStatFailure.

Bigcheese added inline comments.Mar 17 2023, 3:45 PM
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
272–291

Alternative that gets rid of the asserts as you just can't construct it incorrectly. I didn't compile this locally, but this should make it so you can't use {} to construct one externally, and you either use:

PathPolicy::cache(ScanFile::Yes, CacheStatFailure::No) or
PathPolicy::bypassCache()

when constructing them.

Use named constructors instead of an argument to PathPolicy, add unit tests.

Use brace initialization in named constructors

Disable brace initialization

Improve member documentation

Bigcheese accepted this revision.Mar 17 2023, 5:33 PM

lgtm, thanks!

This revision was landed with ongoing or failed builds.Mar 20 2023, 11:12 AM
This revision was automatically updated to reflect the committed changes.