Skip to content

Commit f85e56d

Browse files
committed
ELFView performance fix: avoid calling GetSectionsAt in the innerloop
When the section list gets large GetSectionsAt becomes quite slow instead the the whole list of sections outside the loop and just encour that hit once. It could probably be made even faster if we used an interval tree but then we have to pay the cost of building the tree which may be more nauanced
1 parent 66b9332 commit f85e56d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

view/elf/elfview.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ bool ElfView::Init()
12541254
}
12551255

12561256
size_t commonSegmentOffset = 0;
1257+
auto allSections = GetSections();
12571258
for (auto entry = combinedSymbolTable.begin(); entry != combinedSymbolTable.end(); entry++)
12581259
{
12591260
if (entry->section == ELF_SHN_COMMON)
@@ -1273,13 +1274,19 @@ bool ElfView::Init()
12731274

12741275
// Object files "entry.value" is section relative
12751276
uint64_t adjustedSectionAddr = m_elfSections[entry->section].address + imageBaseAdjustment;
1276-
auto secs = GetSectionsAt(adjustedSectionAddr);
1277-
if (secs.size() < 1)
1278-
continue;
1279-
1280-
entry->value += secs[0]->GetStart();
1281-
}
1282-
else
1277+
// Get the section who contains the adjustedSectionAddr
1278+
// We avoid using GetSectionAt() here as when the list of sections grows large calling this in an
1279+
// inner loop can be very slow.
1280+
for (const auto& section : allSections)
1281+
{
1282+
if (adjustedSectionAddr >= section->GetStart() &&
1283+
adjustedSectionAddr < section->GetEnd())
1284+
{
1285+
entry->value += section->GetStart();
1286+
break;
1287+
}
1288+
}
1289+
} else
12831290
entry->value += imageBaseAdjustment;
12841291

12851292
if (entry->section == ELF_SHN_UNDEF)

0 commit comments

Comments
 (0)