Skip to content

Commit d4e6e40

Browse files
jeffreytan81jeffreytan81
and
jeffreytan81
authored
Improve debug names index fetching global variables performance (#70231)
While using dwarf5 `.debug_names` in internal large targets, we noticed a performance issue (around 10 seconds delay) while `lldb-vscode` tries to show `scopes` for a compile unit. Profiling shows the bottleneck is inside `DebugNamesDWARFIndex::GetGlobalVariables` which linearly search all index entries belongs to a compile unit. This patch improves the performance by using the compile units list to filter first before checking index entries. This significantly improves the performance (drops from 10 seconds => under 1 second) in the split dwarf situation because each compile unit has its own named index. --------- Co-authored-by: jeffreytan81 <[email protected]>
1 parent 20d2102 commit d4e6e40

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,19 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
129129
DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) {
130130
uint64_t cu_offset = cu.GetOffset();
131131
bool found_entry_for_cu = false;
132-
for (const DebugNames::NameIndex &ni: *m_debug_names_up) {
133-
for (DebugNames::NameTableEntry nte: ni) {
132+
for (const DebugNames::NameIndex &ni : *m_debug_names_up) {
133+
// Check if this name index contains an entry for the given CU.
134+
bool cu_matches = false;
135+
for (uint32_t i = 0; i < ni.getCUCount(); ++i) {
136+
if (ni.getCUOffset(i) == cu_offset) {
137+
cu_matches = true;
138+
break;
139+
}
140+
}
141+
if (!cu_matches)
142+
continue;
143+
144+
for (DebugNames::NameTableEntry nte : ni) {
134145
uint64_t entry_offset = nte.getEntryOffset();
135146
llvm::Expected<DebugNames::Entry> entry_or = ni.getEntry(&entry_offset);
136147
for (; entry_or; entry_or = ni.getEntry(&entry_offset)) {

0 commit comments

Comments
 (0)