Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
[XRay] Reserve memory space ahead-of-time when reading native format …
Browse files Browse the repository at this point in the history
…log (#76853)

XRay used to struggle reading large log files. It turned out the
bottleneck was primarily caused by the reallocation happens when
appending log entries into a std::vector.
This patch reserves the memory space ahead-of-time since the number of
entries is known for most cases. Making llvm-xray runs 1.8 times faster
and uses 1.4 times less physical memory when reading large (~2.6GB) log
files.
  • Loading branch information
mshockwave authored Jan 13, 2024
1 parent 5ca2d75 commit 3edf82d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/XRay/Trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian,
return FileHeaderOrError.takeError();
FileHeader = std::move(FileHeaderOrError.get());

size_t NumReservations = llvm::divideCeil(Reader.size() - OffsetPtr, 32U);
Records.reserve(NumReservations);

// Each record after the header will be 32 bytes, in the following format:
//
// (2) uint16 : record type
Expand Down

0 comments on commit 3edf82d

Please sign in to comment.