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.
This commit is contained in:
Jan Voung authored and GitHub committed 2024-06-20 21:04:14 -04:00
1 parent 2fe8498654
commit e1e5ed5893
1 file changed
+7 -1
+7 -1
View File
@@ -7333,7 +7333,13 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef<uint64_t> Record,
bool IsOldProfileFormat,
bool HasProfile, bool HasRelBF) {
std::vector<FunctionSummary::EdgeTy> 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;