[llvm] 3edf82d - [XRay] Reserve memory space ahead-of-time when reading native format log (#76853)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 12 16:34:43 PST 2024
Author: Min-Yih Hsu
Date: 2024-01-12T16:34:39-08:00
New Revision: 3edf82d5566ed5c9898f52b5591c05f6366d6bac
URL: https://github.com/llvm/llvm-project/commit/3edf82d5566ed5c9898f52b5591c05f6366d6bac
DIFF: https://github.com/llvm/llvm-project/commit/3edf82d5566ed5c9898f52b5591c05f6366d6bac.diff
LOG: [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.
Added:
Modified:
llvm/lib/XRay/Trace.cpp
Removed:
################################################################################
diff --git a/llvm/lib/XRay/Trace.cpp b/llvm/lib/XRay/Trace.cpp
index b870adf565459f..74515b16417da3 100644
--- a/llvm/lib/XRay/Trace.cpp
+++ b/llvm/lib/XRay/Trace.cpp
@@ -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
More information about the llvm-commits
mailing list