Skip to content

Commit 3edf82d

Browse files
authored
[XRay] Reserve memory space ahead-of-time when reading native format 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.
1 parent 5ca2d75 commit 3edf82d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

llvm/lib/XRay/Trace.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Error loadNaiveFormatLog(StringRef Data, bool IsLittleEndian,
5151
return FileHeaderOrError.takeError();
5252
FileHeader = std::move(FileHeaderOrError.get());
5353

54+
size_t NumReservations = llvm::divideCeil(Reader.size() - OffsetPtr, 32U);
55+
Records.reserve(NumReservations);
56+
5457
// Each record after the header will be 32 bytes, in the following format:
5558
//
5659
// (2) uint16 : record type

0 commit comments

Comments
 (0)