Replies: 1 comment
-
|
I have not thought much about the details of the proposed fix but it's certainly good to avoid trips to the filesystem and likely a big improvement if your design does a lot of library searching. Is this slowness something you're experiencing yourself with your own projects? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What do you think of the proposal below (by Opus)
Proposal: Speed up
SourceLoader::loadTrees()with directory pre-scanningProblem
loadTrees()insource/driver/SourceLoader.cppresolves missing module/packagenames by probing the filesystem with
findBuffer(). For each missing name, ititerates
searchDirectories × searchExtensionsand callssourceManager.readSource()(which calls
openCached()). Even cache hits go throughfs::weakly_canonical()before the lookup, causing a filesystem round trip per probe.
On network filesystems (NFS), each
stat()/weakly_canonical()is a ~1–5ms networkcall. With M missing names, D search directories, and E extensions, this produces
M × D × Efilesystem calls per iteration of the fixpoint loop. A typical case(50 missing names, 10 directories, 3 extensions) generates ~1,500 NFS round trips
per iteration.
Proposed fix
Replace the per-name probing in
findBuffer()with an upfront directory scan.Scan each search directory once with
readdir()(one syscall per directory), buildan in-memory
flat_hash_map<string, fs::path>keyed by filename stem, then do O(1)lookups for each missing name.
Current code (
findBuffer, lines 187–205)Proposed replacement
Add
flat_hash_map<std::string, fs::path> libraryIndex;as a member ofSourceLoader, and callbuildLibraryIndex()once at the top ofloadTrees()(or lazily on first
findBuffer()call).Impact
D × Estat/canonicalizeDreaddir calls (once)The index also eliminates
weakly_canonical()calls on the lookup path sincedirectory entries from
fs::directory_iteratoralready provide canonical paths.Notes
directory_iteratorhandles the case where a search directory doesn't exist(returns empty range with error code).
try_emplacegives priorityto the first directory in order, matching the current left-to-right search
behavior.
directories are expected to change during compilation (unlikely in practice).
Beta Was this translation helpful? Give feedback.
All reactions