This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFCI] Replace use of DWARFAttribute in DWARFAbbreviationDecl
ClosedPublic

Authored by bulbazord on May 11 2023, 7:19 PM.

Details

Summary

DWARFAttribute is used in 2 classes: DWARFAbbreviationDecl and
DWARFAttributes. The former stores a std::vector of them and the latter
has a small structure called AttributeValue that contains a
DWARFAttribute. DWARFAttributes maintains a llvm::SmallVector of
AttributeValues.

My end goal is to have DWARFAttributes have a llvm::SmallVector
specialized on DWARFAttribute. In order to do that, we'll have to move
the other elements of AttributeValue into DWARFAttribute itself. But we
don't want to do this while DWARFAbbreviationDecl is using
DWARFAttribute because it will needlessly increase the size of
DWARFAbbreviationDecl. So instead I will create a small type containing
only what DWARFAbbreviationDecl needs and call it AttributeSpec. This
is the exact same thing that LLVM does today.

I've elected to swap std::vector for llvm::SmallVector here with a pre-allocated
size of 8. I've collected time and memory measurements before this change and
after it as well. Using a c++ project with 10,000 object files and no dSYM, I
place a breakpoint by file + lineno and see how long it takes to resolve.

Before this patch:

Time (mean ± σ):     13.577 s ±  0.024 s    [User: 12.418 s, System: 1.247 s]

Total number of bytes allocated: 1.38 GiB
Total number of allocations: 6.47 million allocations

After this patch:

Time (mean ± σ):     13.287 s ±  0.020 s    [User: 12.128 s, System: 1.250 s]

Total number of bytes allocated: 1.59 GiB
Total number of allocations: 4.61 million allocations

So we consume more memory than before, but we actually make less allocations on
average.

I also measured with an llvm::SmallVector with a pre-allocated size of 4 instead
of 8 to measure how well it performs:

Time (mean ± σ):     13.246 s ±  0.048 s    [User: 12.074 s, System: 1.268 s]

Total memory consumption: 1.50 GiB
Total number of allocations: 5.74 million

Of course this data may look very different depending on the actual program
being debugged, but each of the object files had 100+ AbbreviationDeclarations
each with between 0 and 10 Attributes, so I feel this was a fair example to
consider.

Diff Detail

Event Timeline

bulbazord created this revision.May 11 2023, 7:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2023, 7:19 PM
bulbazord requested review of this revision.May 11 2023, 7:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2023, 7:19 PM

I previously uploaded a similar patch that I've since abandoned. It contains valuable context so I'm linking it here for other contributors to read: D149214

JDevlieghere accepted this revision.May 12 2023, 2:48 AM

Given the numbers I'm surprised you decided to stick with 8 rather than 4? Unless I'm reading them wrong, it seems that despite the number of allocations, it's about as fast and uses (a bit) less memory. Besides that this LGTM.

lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
58

This could be an emplace_back.

This revision is now accepted and ready to land.May 12 2023, 2:48 AM

Given the numbers I'm surprised you decided to stick with 8 rather than 4? Unless I'm reading them wrong, it seems that despite the number of allocations, it's about as fast and uses (a bit) less memory. Besides that this LGTM.

Yeah, I just forgot to update this before I published. Will update the patch before landing. Thanks for the review!

bulbazord updated this revision to Diff 521771.May 12 2023, 1:11 PM
  • Use emplace_back
  • llvm::SmallVector size 8 -> 4
This revision was landed with ongoing or failed builds.May 12 2023, 1:13 PM
This revision was automatically updated to reflect the committed changes.