This is an archive of the discontinued LLVM Phabricator instance.

[SourceManager] Improve getFileIDLoaded.
ClosedPublic

Authored by hokein on Oct 5 2022, 4:58 AM.

Details

Summary

Similar to getFileIDLocal patch, but for the version for load module.

Test with clangd (building AST with preamble), FileID scans in binary
search is reduced:

SemaExpr.cpp: 142K -> 137K (-3%)
FindTarget.cpp: 368K -> 343K (-6%)

Diff Detail

Event Timeline

hokein created this revision.Oct 5 2022, 4:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 4:58 AM
Herald added a subscriber: kadircet. · View Herald Transcript
hokein requested review of this revision.Oct 5 2022, 4:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 4:58 AM
sammccall accepted this revision.Oct 5 2022, 7:14 AM

Nice!

Just a couple of comments where we could take the opportunity to clarify the existing code. Optional.

clang/lib/Basic/SourceManager.cpp
880

This is confusing: if SLocEntry.getOffset() > SLocOffset then it means SLocOffset is *not* part the entry (entry can be pruned), but if they're equal it means it *is* part of the entry (entry should not be pruned).
Then we're pruning the entry regardless.

I think we're getting away with this because we never get here in the == case as we would have hit the cache.
But > seems clearer than >=, assuming my analysis is right.

881

I believe the +1 here is in order to exclude LastFileIDLookup.ID, and again the justification is that we would otherwise have hit the cache.

I think a short comment // Exclude LastID, else we would have hit the cache would help here

This revision is now accepted and ready to land.Oct 5 2022, 7:14 AM
This revision was automatically updated to reflect the committed changes.
hokein marked 2 inline comments as done.