Skip to content

Commit e96c444

Browse files
cachemeifyoucantru
authored andcommitted
[SymbolSize] Improve the performance of SymbolSize computation
The current algorithm to compute the symbol size is quadratic if there are lots of symbols sharing the same addresses. This happens in a debug build when lots of debug symbols get emitted in the symtab. This patch improves the performance like `llvm-symbolizer` that relies on the symbol size computation. Symbolizing a release+assert clang with DebugInfo sees significant improvements from 3:40min to less than 1s. Reviewed By: pete, mehdi_amini, arsenm, MaskRay Differential Revision: https://reviews.llvm.org/D156603 (cherry picked from commit f5974e8)
1 parent a6bc750 commit e96c444

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

llvm/lib/Object/SymbolSize.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,21 @@ llvm::object::computeSymbolSizes(const ObjectFile &O) {
8484

8585
array_pod_sort(Addresses.begin(), Addresses.end(), compareAddress);
8686

87-
// Compute the size as the gap to the next symbol
88-
for (unsigned I = 0, N = Addresses.size() - 1; I < N; ++I) {
87+
// Compute the size as the gap to the next symbol. If multiple symbols have
88+
// the same address, give both the same size. Because Addresses is sorted,
89+
// using two pointers to keep track of the current symbol vs. the next symbol
90+
// that doesn't have the same address for size computation.
91+
for (unsigned I = 0, NextI = 0, N = Addresses.size() - 1; I < N; ++I) {
8992
auto &P = Addresses[I];
9093
if (P.I == O.symbol_end())
9194
continue;
9295

93-
// If multiple symbol have the same address, give both the same size.
94-
unsigned NextI = I + 1;
95-
while (NextI < N && Addresses[NextI].Address == P.Address)
96-
++NextI;
96+
// If the next pointer is behind, update it to the next symbol.
97+
if (NextI <= I) {
98+
NextI = I + 1;
99+
while (NextI < N && Addresses[NextI].Address == P.Address)
100+
++NextI;
101+
}
97102

98103
uint64_t Size = Addresses[NextI].Address - P.Address;
99104
P.Address = Size;

0 commit comments

Comments
 (0)