Skip to content

Commit f1cb8ef

Browse files
committedDec 14, 2017
[ProfileData] Use a different data structure to save memory.
This change swaps FunctionSamples to a std::map. This saves us around 17% of the memory required to parse sample profiles. To put hard numbers on this, clang now eats around 1.3GB of RAM instead of 1.6GB while parsing a 50MB profile. The CPU time taken by a large profile merge (3.1GB of data across 226 files) is also reduced by ~11% by this patch (1:09.08 vs 1:01.11). This was split out at the request of reviewers in D41152. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320764 91177308-0d34-0410-b5e6-96231b3b80d8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎include/llvm/ProfileData/SampleProf.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample);
185185
class FunctionSamples;
186186

187187
using BodySampleMap = std::map<LineLocation, SampleRecord>;
188-
using FunctionSamplesMap = StringMap<FunctionSamples>;
188+
// NOTE: Using a StringMap here makes parsed profiles consume around 17% more
189+
// memory, which is *very* significant for large profiles.
190+
using FunctionSamplesMap = std::map<std::string, FunctionSamples>;
189191
using CallsiteSampleMap = std::map<LineLocation, FunctionSamplesMap>;
190192

191193
/// Representation of the samples collected for a function.
@@ -278,7 +280,7 @@ class FunctionSamples {
278280
return nullptr;
279281
auto FS = iter->second.find(CalleeName);
280282
if (FS != iter->second.end())
281-
return &FS->getValue();
283+
return &FS->second;
282284
// If we cannot find exact match of the callee name, return the FS with
283285
// the max total count.
284286
uint64_t MaxTotalSamples = 0;
@@ -347,7 +349,7 @@ class FunctionSamples {
347349
const LineLocation &Loc = I.first;
348350
FunctionSamplesMap &FSMap = functionSamplesAt(Loc);
349351
for (const auto &Rec : I.second)
350-
MergeResult(Result, FSMap[Rec.first()].merge(Rec.second, Weight));
352+
MergeResult(Result, FSMap[Rec.first].merge(Rec.second, Weight));
351353
}
352354
return Result;
353355
}

0 commit comments

Comments
 (0)
Please sign in to comment.