[llvm] [memprof] Omit the key length for the call stack table (PR #89510)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 20 10:47:21 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/89510

The call stack 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.64% of the indexed MemProf file size.

Note that it's OK to change the format because Version2 is still under
development.


>From 2587c61244656f81a7fba9b3944fc6023cd63c34 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 19 Apr 2024 23:42:52 -0700
Subject: [PATCH] [memprof] Omit the key length for the call stack table

The call stack 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.64% of the indexed MemProf file size.

Note that it's OK to change the format because Version2 is still under
development.
---
 llvm/include/llvm/ProfileData/MemProf.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index faaec331c823ed..7bdeeffc1dbc2e 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -651,8 +651,8 @@ class CallStackWriterTrait {
   EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) {
     using namespace support;
     endian::Writer LE(Out, llvm::endianness::little);
+    // We do not explicitly emit the key length because it is a constant.
     offset_type N = sizeof(K);
-    LE.write<offset_type>(N);
     offset_type M = sizeof(FrameId) * V.size();
     LE.write<offset_type>(M);
     return std::make_pair(N, M);
@@ -696,8 +696,8 @@ class CallStackLookupTrait {
   ReadKeyDataLength(const unsigned char *&D) {
     using namespace support;
 
-    offset_type KeyLen =
-        endian::readNext<offset_type, llvm::endianness::little>(D);
+    // We do not explicitly read the key length because it is a constant.
+    offset_type KeyLen = sizeof(external_key_type);
     offset_type DataLen =
         endian::readNext<offset_type, llvm::endianness::little>(D);
     return std::make_pair(KeyLen, DataLen);



More information about the llvm-commits mailing list