From f1cb8efedeb65da55ff87449a6c83ad7e839b090 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Thu, 14 Dec 2017 23:32:57 +0000 Subject: [PATCH] [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 --- include/llvm/ProfileData/SampleProf.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/llvm/ProfileData/SampleProf.h b/include/llvm/ProfileData/SampleProf.h index 48cb5016659..9eccafc65f3 100644 --- a/include/llvm/ProfileData/SampleProf.h +++ b/include/llvm/ProfileData/SampleProf.h @@ -185,7 +185,9 @@ raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample); class FunctionSamples; using BodySampleMap = std::map; -using FunctionSamplesMap = StringMap; +// NOTE: Using a StringMap here makes parsed profiles consume around 17% more +// memory, which is *very* significant for large profiles. +using FunctionSamplesMap = std::map; using CallsiteSampleMap = std::map; /// Representation of the samples collected for a function. @@ -278,7 +280,7 @@ public: return nullptr; auto FS = iter->second.find(CalleeName); if (FS != iter->second.end()) - return &FS->getValue(); + return &FS->second; // If we cannot find exact match of the callee name, return the FS with // the max total count. uint64_t MaxTotalSamples = 0; @@ -347,7 +349,7 @@ public: const LineLocation &Loc = I.first; FunctionSamplesMap &FSMap = functionSamplesAt(Loc); for (const auto &Rec : I.second) - MergeResult(Result, FSMap[Rec.first()].merge(Rec.second, Weight)); + MergeResult(Result, FSMap[Rec.first].merge(Rec.second, Weight)); } return Result; } -- 2.11.0