[llvm] b28f4d4 - [memprof] Omit the key length for the record table (#89527)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 22 22:59:55 PDT 2024
Author: Kazu Hirata
Date: 2024-04-22T22:59:51-07:00
New Revision: b28f4d4dd0bbf50059cb19ca794af967374e1900
URL: https://github.com/llvm/llvm-project/commit/b28f4d4dd0bbf50059cb19ca794af967374e1900
DIFF: https://github.com/llvm/llvm-project/commit/b28f4d4dd0bbf50059cb19ca794af967374e1900.diff
LOG: [memprof] Omit the key length for the record table (#89527)
The record table has a constant key length, so we don't need to
serialize or deserialize it for every key-data pair. Omitting the key
length saves 0.06% of the indexed MemProf file size.
Note that it's OK to change the format because Version2 is still under
development.
Added:
Modified:
llvm/include/llvm/ProfileData/MemProf.h
llvm/include/llvm/Support/OnDiskHashTable.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index aa6cdf198485b0..f356e3a54a3645 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -471,12 +471,16 @@ class RecordLookupTrait {
hash_value_type ComputeHash(uint64_t K) { return K; }
- static std::pair<offset_type, offset_type>
+ std::pair<offset_type, offset_type>
ReadKeyDataLength(const unsigned char *&D) {
using namespace support;
+ // Starting with Version2, we don't read the key length because it is a
+ // constant.
offset_type KeyLen =
- endian::readNext<offset_type, llvm::endianness::little>(D);
+ Version < Version2
+ ? endian::readNext<offset_type, llvm::endianness::little>(D)
+ : sizeof(uint64_t);
offset_type DataLen =
endian::readNext<offset_type, llvm::endianness::little>(D);
return std::make_pair(KeyLen, DataLen);
@@ -534,7 +538,9 @@ class RecordWriterTrait {
endian::Writer LE(Out, llvm::endianness::little);
offset_type N = sizeof(K);
- LE.write<offset_type>(N);
+ // Starting with Version2, we omit the key length because it is a constant.
+ if (Version < Version2)
+ LE.write<offset_type>(N);
offset_type M = V.serializedSize(Version);
LE.write<offset_type>(M);
return std::make_pair(N, M);
diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/include/llvm/Support/OnDiskHashTable.h
index f6b4055e74de7e..b6dbea53f3da6d 100644
--- a/llvm/include/llvm/Support/OnDiskHashTable.h
+++ b/llvm/include/llvm/Support/OnDiskHashTable.h
@@ -377,7 +377,7 @@ template <typename Info> class OnDiskChainedHashTable {
// Determine the length of the key and the data.
const std::pair<offset_type, offset_type> &L =
- Info::ReadKeyDataLength(Items);
+ InfoPtr->ReadKeyDataLength(Items);
offset_type ItemLen = L.first + L.second;
// Compare the hashes. If they are not the same, skip the entry entirely.
More information about the llvm-commits
mailing list