-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[DebugInfo] Add fast path for parsing DW_TAG_compile_unit abbrevs #108757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BertalanD
wants to merge
3
commits into
llvm:main
Choose a base branch
from
BertalanD:dwarf-parser-fast-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this either generalize this to check the first abbrev in the table, regardless of numbering - or change abbrev parsing to be lazy in general? (like parse as much of the table as is needed to find the number - oh, I guess we do have some optimizations that only fire if the abbrev numbering is strictly increasing (doesn't have to start at 1, doesn't have to increase by 1 each time - but so long as it's always increasing we can still binary search))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with David here, this is seems like an overfit. Both suggestions make sense to me, either check the first entry in the table (which seems to be what you're doing anyway) or make abbreviation parsing lazier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have considered this, but this would likely pessimize the general case.
Profiling shows that the majority of
ld64.lld
's DWARF parsing time is split evenly between ULEB128 parsing and appending to theDWARFAbbreviationDeclaration::attribute_specs
vector.As far as I can tell, everything is ULEB128-encoded in the abbrev table, so if we do it lazily, we'll end up constantly re-parsing the abbrev declarations that come before the one we're looking for. So we'd parse these numbers
O(n^2)
times instead ofO(n)
. I guess we could do a first pass where we only note down the begin offsets of the abbreviations, but that would bring us back to the situation with the large number of vector appends (although the count is|abbrevs|
, not|attributes|
, that might be better)And if we do need everything, the total cost of building e.g. an
std::map
would end up being larger than the vector appends' cost. For the use cases where everything is needed (LLDB, dsymutil, etc.), constructing the single sorted vector upfront (i.e. whatDWARFAbbreviationDeclarationSet
does) is faster than the above approach.Do you mean always trying to parse the first abbreviation (so no
AbbrCode == 1
check), and checking afterwards if the code happens to be what we need? That sounds okay to me, since after the first call, the value is cached, so its cost would be a singlestd::map
lookup.Just out of curiosity, how common is the first abbreviation code not being 1 or code 1 not being
DW_TAG_compile_unit
? All C++/Swift/Rust programs I tested hit my fast path.Flame graph of DWARF parsing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(re 1: Agreed, it's not common in LLVM, but
if (0 == AbbrCode) {
is just 7 lines above in this file. So it does match local style.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, not /that/ lazy. Like we could store the existing vector of abbrevs, and an offset to past the end of the last abbrev we parsed (or some sentinel if we reached the end of the abbrev list, with its 0 marker). Then if an abbrev number is requested that isn't in the list already, we parse abbrevs (& put them in the vector, etc) until we find the one we're looking for.
But I think the only place I'm thinking of that'd benefit from lazy abbrev parsing is just for the CU abbrev too anyway (building an address lookup table when the DWARF doesn't include .debug_aranges - currently that involves parsing all the abbrevs, and should only need the CU's abbrev too)
& also there's some code in llvm-dwp that tries to parse just the first CU to access the dwo_id for DWARFv4. Though I'm not sure that code's using libDebugInfoDWARF at all, since it mostly doesn't need to parse DWARF.
I guess it'd help to be more generalized laziness would handle cases where the CU DIE abbrev isn't the first one (like with type units, but those aren't used on MacOS, so aren't relevant to ld64 perf).
Why is ld64 reading the CUs anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(will reflect on the other bits later):
For emitting
N_OSO
stabs; which indicate the source file names of symbols. We need to readDW_AT_source_dir
for this, seeObjFile::sourceFile
in LLD.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One generalization would be to try symbolizing (llvm-symbolizer) where the abbrev parsing probably isn't /as/ large a part of the profile, but probably it shows up and lazy CU abbrev parsing probably helps there too?