Skip to content

Improve debug names index fetching global variables performance #70231

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

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,19 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) {
uint64_t cu_offset = cu.GetOffset();
bool found_entry_for_cu = false;
for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
for (DebugNames::NameTableEntry nte: ni) {
for (const DebugNames::NameIndex &ni : *m_debug_names_up) {
// Check if this name index contains an entry for the given CU.
bool cu_matches = false;
for (uint32_t i = 0; i < ni.getCUCount(); ++i) {
if (ni.getCUOffset(i) == cu_offset) {
Comment on lines +135 to +136
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If NameIndex exposed the CUOffsets as a range (which seems pretty easy/reasonable for it to do - ah, because it requires potentially applying relocations it'd probably require a custom iterator - maybe a mapped iterator would be adequate & easy to do) then this could be written as:

if (llvm::none_of(ni.CUOffsets(), [&](uint64_t off) { return off == cu_offset; }))
  continue;

I /think/ CUOffsets() would look something roughly like this:

auto CUOffsets() const {
  assert(TU < Hdr.CompUnitCount);
  const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize(Hdr.Format);
  uint64_t Offset = CUsBase + SectionOffsetSize * CU;
  auto R = /* Guess we need some sort of generator to produce the values 
    [CUsBase, CUsBase+SectionOffsetSize*Hdr.CompUnitCount) in SectionOffsetSize increments... 
    some enhancement to llvm::seq that takes a stride size would be suitable */
  return llvm::map_range(llvm::seq(CUsBase, 
      [&](uint64_t Offset) {
        return Section.AccelSection.getRelocatedValue(SectionOffsetSize, &Offset);
      });
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, also, if you kept the result (more like a llvm::find_if as @bulbazord was suggesting, rather than my llvm::none_of here) of this search, you could save a small amount of time (no need to indirect through the index and reapply relocations to get the CU offset) by using getCUInedx() and comparing that to the index you would've found in this search - down on line 139/150

cu_matches = true;
break;
}
}
if (!cu_matches)
continue;
Comment on lines +134 to +142
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great if we could use some kind of find_if instead of manually walking the CU Offsets.


for (DebugNames::NameTableEntry nte : ni) {
uint64_t entry_offset = nte.getEntryOffset();
llvm::Expected<DebugNames::Entry> entry_or = ni.getEntry(&entry_offset);
for (; entry_or; entry_or = ni.getEntry(&entry_offset)) {
Expand Down