diff options
| author | Peter LaFosse <peter@vector35.com> | 2025-08-14 11:20:19 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2025-08-14 11:20:19 -0400 |
| commit | f85e56d1772a8bbaad259f201b604613818c0591 (patch) | |
| tree | 25b8c0f74719acb81da3616c91e5d48212500534 /view | |
| parent | 66b933288095071fb19f6124af14c812e58c09bd (diff) | |
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
Diffstat (limited to 'view')
| -rw-r--r-- | view/elf/elfview.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
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) |
