[llvm] a65c720 - [ProfileData] Split EagerSampleProfileNameTable by key type (NFC) (#211126)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 14:49:38 PDT 2026


Author: Kazu Hirata
Date: 2026-07-24T14:49:33-07:00
New Revision: a65c7202d43ef32e93abef1b36150f07e5c91457

URL: https://github.com/llvm/llvm-project/commit/a65c7202d43ef32e93abef1b36150f07e5c91457
DIFF: https://github.com/llvm/llvm-project/commit/a65c7202d43ef32e93abef1b36150f07e5c91457.diff

LOG: [ProfileData] Split EagerSampleProfileNameTable by key type (NFC) (#211126)

This patch splits EagerSampleProfileNameTable into two separate
classes, EagerStringSampleProfileNameTable and
EagerMD5SampleProfileNameTable.  This patch is meant to be a
preparation patch for centralizing and speeding up symbol membership
queries like "is this symbol in the name table?".

Currently, we have two problems with these membership queries:

- Customers build their own data structures like DenseSet<uint64_t> of
  MD5 values and StringSet<> to serve those queries.  That is, the
  sample profile loader does not directly serve those queries.

- There are two places, namely SampleProfileLoader::doInitialization
  and SampleProfileNameSet, where we build identical StringSet<> of the
  name table entries, costing compilation time at both construction and
  destruction time.

Now, we could serve these membership queries from a central place using
DenseSet<uint64_t> of MD5 values, but that would be expensive if we
have a string-based name table because we need to compute MD5 values
for all name table entries.  In that case, we should construct
DenseSet<StringRef> using a cheaper hash function like
llvm::xxh3_64bits instead.

This patch helps us by separating the two cases -- MD5-based and
string-based name table.

In a subsequent patch, I'm planning to implement the "contains" method
so that users can easily ask us whether a given symbol is in the name
table.

RFC:
https://discourse.llvm.org/t/rfc-faster-sample-profile-loading/90957

Assisted-by: Antigravity

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/SampleProfReader.h
    llvm/lib/ProfileData/SampleProfReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index fd7bf8c49374e..0003d06e60373 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -418,13 +418,30 @@ class LazySampleProfileNameTable final : public SampleProfileNameTable {
   }
 };
 
-class EagerSampleProfileNameTable final : public SampleProfileNameTable {
+class StringSampleProfileNameTable final : public SampleProfileNameTable {
   std::vector<FunctionId> Vec;
 
 public:
-  explicit EagerSampleProfileNameTable(std::vector<FunctionId> &&Vec)
+  explicit StringSampleProfileNameTable(std::vector<FunctionId> &&Vec)
       : Vec(std::move(Vec)) {}
-  explicit EagerSampleProfileNameTable(const std::vector<FunctionId> &Vec)
+  explicit StringSampleProfileNameTable(const std::vector<FunctionId> &Vec)
+      : Vec(Vec) {}
+
+  size_t size() const override { return Vec.size(); }
+
+  FunctionId operator[](size_t Idx) const override {
+    assert(Idx < Vec.size() && "Index out of bounds");
+    return Vec[Idx];
+  }
+};
+
+class MD5SampleProfileNameTable final : public SampleProfileNameTable {
+  std::vector<FunctionId> Vec;
+
+public:
+  explicit MD5SampleProfileNameTable(std::vector<FunctionId> &&Vec)
+      : Vec(std::move(Vec)) {}
+  explicit MD5SampleProfileNameTable(const std::vector<FunctionId> &Vec)
       : Vec(Vec) {}
 
   size_t size() const override { return Vec.size(); }

diff  --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 41dfcd059db67..f7e291729a5d9 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -1295,8 +1295,12 @@ std::error_code SampleProfileReaderBinary::readNameTable() {
   }
   if (!ProfileIsCS)
     MD5SampleContextStart = MD5SampleContextTable.data();
-  NameTable =
-      std::make_unique<EagerSampleProfileNameTable>(std::move(TableVec));
+  if (UseMD5)
+    NameTable =
+        std::make_unique<MD5SampleProfileNameTable>(std::move(TableVec));
+  else
+    NameTable =
+        std::make_unique<StringSampleProfileNameTable>(std::move(TableVec));
   return sampleprof_error::success;
 }
 
@@ -1376,7 +1380,7 @@ SampleProfileReaderExtBinaryBase::readNameTableSecLegacy(bool IsMD5,
         TableVec.emplace_back(FunctionId(FID));
       }
       NameTable =
-          std::make_unique<EagerSampleProfileNameTable>(std::move(TableVec));
+          std::make_unique<MD5SampleProfileNameTable>(std::move(TableVec));
     }
     if (!ProfileIsCS)
       MD5SampleContextStart = reinterpret_cast<const uint64_t *>(Data);
@@ -1405,7 +1409,7 @@ SampleProfileReaderExtBinaryBase::readNameTableSecLegacy(bool IsMD5,
     if (!ProfileIsCS)
       MD5SampleContextStart = MD5SampleContextTable.data();
     NameTable =
-        std::make_unique<EagerSampleProfileNameTable>(std::move(TableVec));
+        std::make_unique<MD5SampleProfileNameTable>(std::move(TableVec));
     return sampleprof_error::success;
   }
 


        


More information about the llvm-commits mailing list