From e1e5ed5893c50918dc9b6b56acfe6242f03354dc Mon Sep 17 00:00:00 2001 From: Jan Voung Date: Thu, 20 Jun 2024 21:04:14 -0400 Subject: Update ModuleSummaryIndexBitcodeReader::makeCallList reserve amount (#95461) Tighten the reserve() to `Record.size() / 2` instead of `Record.size()` in the HasProfile/HasRelBF cases. For the uncommon old profile format cases we leave it as is, but those should be rare and not worth optimizing. This reduces peak memory during ThinLTO indexing by ~3% in one example. Alternatively, we could make the branching for reserve more complex and try to cover every case. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 06d9936..6bcd0c1 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -7333,7 +7333,13 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef Record, bool IsOldProfileFormat, bool HasProfile, bool HasRelBF) { std::vector Ret; - Ret.reserve(Record.size()); + // In the case of new profile formats, there are two Record entries per + // Edge. Otherwise, conservatively reserve up to Record.size. + if (!IsOldProfileFormat && (HasProfile || HasRelBF)) + Ret.reserve(Record.size() / 2); + else + Ret.reserve(Record.size()); + for (unsigned I = 0, E = Record.size(); I != E; ++I) { CalleeInfo::HotnessType Hotness = CalleeInfo::HotnessType::Unknown; bool HasTailCall = false; -- cgit v1.1