Skip to content

Commit 3c994a3

Browse files
author
mxms
committed
[ProfData] Improve efficiency of reader
Pre-reserve space in the map before inserting. In release builds, 9.4% of all CPU time is spent in llvm::sampleprof::ProfileSymbolList::add. Of that 9.4%, roughly half is in llvm::DenseMapBase::grow.
1 parent 264d4dd commit 3c994a3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

llvm/lib/ProfileData/SampleProf.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,30 +399,29 @@ LLVM_DUMP_METHOD void FunctionSamples::dump() const { print(dbgs(), 0); }
399399
std::error_code ProfileSymbolList::read(const uint8_t *Data,
400400
uint64_t ListSize) {
401401
const char *ListStart = reinterpret_cast<const char *>(Data);
402-
uint64_t Offset = 0;
402+
uint64_t Size = 0;
403403
uint64_t StrNum = 0;
404404
uint64_t ExpectedCount = 0;
405405

406406
// Scan forward to see how many elements we expect.
407407
while (Offset < ListSize) {
408408
if (ListStart[Offset] == '\0') ExpectedCount++;
409409
Offset++;
410-
}
411410

412411
reserve(ExpectedCount);
413412

414-
Offset = 0;
413+
Size = 0;
415414

416-
while (Offset < ListSize && StrNum < ProfileSymbolListCutOff) {
417-
StringRef Str(ListStart + Offset);
415+
while (Size < ListSize && StrNum < ProfileSymbolListCutOff) {
416+
StringRef Str(ListStart + Size);
418417
add(Str);
419-
Offset += Str.size() + 1;
418+
Size += Str.size() + 1;
420419
StrNum++;
421420
}
422421

423422
assert(ExpectedCount == StrNum);
424423

425-
if (Offset != ListSize && StrNum != ProfileSymbolListCutOff)
424+
if (Size != ListSize && StrNum != ProfileSymbolListCutOff)
426425
return sampleprof_error::malformed;
427426
return sampleprof_error::success;
428427
}

0 commit comments

Comments
 (0)