From f85e56d1772a8bbaad259f201b604613818c0591 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 14 Aug 2025 11:20:19 -0400 Subject: 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 --- view/elf/elfview.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'view/elf/elfview.cpp') diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp index 29914ca7..5bfcd5c8 100644 --- a/view/elf/elfview.cpp +++ b/view/elf/elfview.cpp @@ -1254,6 +1254,7 @@ bool ElfView::Init() } size_t commonSegmentOffset = 0; + auto allSections = GetSections(); for (auto entry = combinedSymbolTable.begin(); entry != combinedSymbolTable.end(); entry++) { if (entry->section == ELF_SHN_COMMON) @@ -1273,13 +1274,19 @@ bool ElfView::Init() // Object files "entry.value" is section relative uint64_t adjustedSectionAddr = m_elfSections[entry->section].address + imageBaseAdjustment; - auto secs = GetSectionsAt(adjustedSectionAddr); - if (secs.size() < 1) - continue; - - entry->value += secs[0]->GetStart(); - } - else + // Get the section who contains the adjustedSectionAddr + // We avoid using GetSectionAt() here as when the list of sections grows large calling this in an + // inner loop can be very slow. + for (const auto& section : allSections) + { + if (adjustedSectionAddr >= section->GetStart() && + adjustedSectionAddr < section->GetEnd()) + { + entry->value += section->GetStart(); + break; + } + } + } else entry->value += imageBaseAdjustment; if (entry->section == ELF_SHN_UNDEF) -- cgit v1.3.1