From a6a2f7849557bb30b79dafb079ef0fc97736fd9f Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 10 Nov 2023 13:01:49 +0100 Subject: reduce memory footprint for bucket indexes (#526) reduces memory footprint of cache index by 10% or so by limiting the maximum number of entries in a bucket to 2^32 (was 2^64) --- src/zenserver/cache/cachedisklayer.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/zenserver/cache/cachedisklayer.h b/src/zenserver/cache/cachedisklayer.h index 99c54e192..4efdeebd7 100644 --- a/src/zenserver/cache/cachedisklayer.h +++ b/src/zenserver/cache/cachedisklayer.h @@ -233,11 +233,11 @@ private: #pragma pack(1) struct MetaDataIndex { - size_t Index = std::numeric_limits::max(); + uint32_t Index = std::numeric_limits::max(); - operator bool() const { return Index != std::numeric_limits::max(); }; + operator bool() const { return Index != std::numeric_limits::max(); }; MetaDataIndex() = default; - explicit MetaDataIndex(size_t Index) : Index(Index) {} + explicit MetaDataIndex(size_t InIndex) : Index(uint32_t(InIndex)) {} operator size_t() const { return Index; }; inline auto operator<=>(const MetaDataIndex& Other) const = default; }; @@ -248,32 +248,32 @@ private: operator bool() const { return Index != std::numeric_limits::max(); }; MemCachedIndex() = default; - explicit MemCachedIndex(uint32_t Index) : Index(Index) {} + explicit MemCachedIndex(uint32_t InIndex) : Index(InIndex) {} operator size_t() const { return Index; }; inline auto operator<=>(const MemCachedIndex& Other) const = default; }; struct ReferenceIndex { - size_t Index = std::numeric_limits::max(); + uint32_t Index = std::numeric_limits::max(); - static const ReferenceIndex Unknown() { return ReferenceIndex{std::numeric_limits::max()}; } - static const ReferenceIndex None() { return ReferenceIndex{std::numeric_limits::max() - 1}; } + static const ReferenceIndex Unknown() { return ReferenceIndex{std::numeric_limits::max()}; } + static const ReferenceIndex None() { return ReferenceIndex{std::numeric_limits::max() - 1}; } ReferenceIndex() = default; - explicit ReferenceIndex(size_t Index) : Index(Index) {} + explicit ReferenceIndex(size_t InIndex) : Index(uint32_t(InIndex)) {} operator size_t() const { return Index; }; - operator bool() const { return Index != std::numeric_limits::max(); }; + operator bool() const { return Index != std::numeric_limits::max(); }; inline auto operator<=>(const ReferenceIndex& Other) const = default; }; struct PayloadIndex { - size_t Index = std::numeric_limits::max(); + uint32_t Index = std::numeric_limits::max(); - operator bool() const { return Index != std::numeric_limits::max(); }; + operator bool() const { return Index != std::numeric_limits::max(); }; PayloadIndex() = default; - explicit PayloadIndex(size_t Index) : Index(Index) {} + explicit PayloadIndex(size_t InIndex) : Index(uint32_t(InIndex)) {} operator size_t() const { return Index; }; inline auto operator<=>(const PayloadIndex& Other) const = default; }; @@ -281,7 +281,7 @@ private: struct BucketPayload { DiskLocation Location; // 12 - MetaDataIndex MetaData; // 8 + MetaDataIndex MetaData; // 4 MemCachedIndex MemCached; // 4 }; struct BucketMetaData @@ -292,7 +292,7 @@ private: operator bool() const { return RawSize != 0 || RawHash != IoHash::Zero; }; }; #pragma pack(pop) - static_assert(sizeof(BucketPayload) == 24u); + static_assert(sizeof(BucketPayload) == 20u); static_assert(sizeof(BucketMetaData) == 28u); static_assert(sizeof(AccessTime) == 4u); -- cgit v1.2.3