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.
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.