Skip to content

Commit b28f4d4

Browse files
[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.
1 parent 02d00ec commit b28f4d4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,16 @@ class RecordLookupTrait {
471471

472472
hash_value_type ComputeHash(uint64_t K) { return K; }
473473

474-
static std::pair<offset_type, offset_type>
474+
std::pair<offset_type, offset_type>
475475
ReadKeyDataLength(const unsigned char *&D) {
476476
using namespace support;
477477

478+
// Starting with Version2, we don't read the key length because it is a
479+
// constant.
478480
offset_type KeyLen =
479-
endian::readNext<offset_type, llvm::endianness::little>(D);
481+
Version < Version2
482+
? endian::readNext<offset_type, llvm::endianness::little>(D)
483+
: sizeof(uint64_t);
480484
offset_type DataLen =
481485
endian::readNext<offset_type, llvm::endianness::little>(D);
482486
return std::make_pair(KeyLen, DataLen);
@@ -534,7 +538,9 @@ class RecordWriterTrait {
534538

535539
endian::Writer LE(Out, llvm::endianness::little);
536540
offset_type N = sizeof(K);
537-
LE.write<offset_type>(N);
541+
// Starting with Version2, we omit the key length because it is a constant.
542+
if (Version < Version2)
543+
LE.write<offset_type>(N);
538544
offset_type M = V.serializedSize(Version);
539545
LE.write<offset_type>(M);
540546
return std::make_pair(N, M);

llvm/include/llvm/Support/OnDiskHashTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ template <typename Info> class OnDiskChainedHashTable {
377377

378378
// Determine the length of the key and the data.
379379
const std::pair<offset_type, offset_type> &L =
380-
Info::ReadKeyDataLength(Items);
380+
InfoPtr->ReadKeyDataLength(Items);
381381
offset_type ItemLen = L.first + L.second;
382382

383383
// Compare the hashes. If they are not the same, skip the entry entirely.

0 commit comments

Comments
 (0)