From 7a4bf22ac5330024b4b807c9f7cf42292a5135d1 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 23 Jul 2024 14:07:48 +0200 Subject: Reduce the size of large object entries. Removed named keys of entries (hash, size). These prefixes were added for every chunk creating an additional overhead without any benefit. Removed prefixes of hashes (*62*hash) appearing in native mode and creating an additional overhead as well: it is known that all of them are blobs. --- src/buildtool/storage/large_object_cas.tpp | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/buildtool/storage/large_object_cas.tpp b/src/buildtool/storage/large_object_cas.tpp index 0f79b231..dae1d696 100644 --- a/src/buildtool/storage/large_object_cas.tpp +++ b/src/buildtool/storage/large_object_cas.tpp @@ -29,6 +29,11 @@ #include "src/buildtool/storage/large_object_cas.hpp" #include "src/buildtool/storage/local_cas.hpp" +namespace { +inline constexpr std::size_t kHashIndex = 0; +inline constexpr std::size_t kSizeIndex = 1; +} // namespace + template auto LargeObjectCAS::GetEntryPath( bazel_re::Digest const& digest) const noexcept @@ -66,15 +71,14 @@ auto LargeObjectCAS::ReadEntry( try { std::ifstream stream(*file_path); nlohmann::json j = nlohmann::json::parse(stream); - const std::size_t size = j.at("size").template get(); - parts.reserve(size); - - auto const& j_parts = j.at("parts"); - for (std::size_t i = 0; i < size; ++i) { - bazel_re::Digest& d = parts.emplace_back(); - d.set_hash(j_parts.at(i).at("hash").template get()); - d.set_size_bytes( - j_parts.at(i).at("size").template get()); + parts.reserve(j.size()); + + for (auto const& j_part : j) { + auto hash = j_part.at(kHashIndex).template get(); + auto size = j_part.at(kSizeIndex).template get(); + + parts.emplace_back( + ArtifactDigest{std::move(hash), size, /*is_tree=*/false}); } } catch (...) { return std::nullopt; @@ -100,12 +104,12 @@ auto LargeObjectCAS::WriteEntry( nlohmann::json j; try { - j["size"] = parts.size(); - auto& j_parts = j["parts"]; for (auto const& part : parts) { - auto& j = j_parts.emplace_back(); - j["hash"] = part.hash(); - j["size"] = part.size_bytes(); + auto& j_part = j.emplace_back(); + + ArtifactDigest const a_digest(part); + j_part[kHashIndex] = a_digest.hash(); + j_part[kSizeIndex] = a_digest.size(); } } catch (...) { return false; -- cgit v1.2.3