From 391088900e269b95710c4fa9e97e26cbe68435df Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sun, 21 Jul 2024 11:28:23 +0200 Subject: [PATCH] libstore/binary-cache-store: use correct buffer size for NAR decompression Due to a leftover from a previous version where the buffer was allocated on the stack, the change introduced in commit 4ec87742a196d8ed8f41b41ef039706ce791448d accidentally passes the size of a pointer as the size of the buffer to the decompressor. Since the former is much smaller (usually 8 bytes instead of 64 kilobytes), this is safe, but leads to considerable overhead; most notably, due to excessive progress reports, which happen for each chunk. Pass the proper buffer size instead. Change-Id: If4bf472d33e21587acb5235a2d99e3cb10914633 --- src/libstore/binary-cache-store.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index e507391fe..6ab5a0a1c 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -336,12 +336,13 @@ WireFormatGenerator BinaryCacheStore::narFromPath(const StorePath & storePath) try { auto file = getFile(info->url); return [](auto info, auto file, auto & stats) -> WireFormatGenerator { - std::unique_ptr buf(new char[65536]); + constexpr size_t buflen = 65536; + auto buf = std::make_unique(buflen); size_t total = 0; auto decompressor = makeDecompressionSource(info->compression, *file); try { while (true) { - const auto len = decompressor->read(buf.get(), sizeof(buf)); + const auto len = decompressor->read(buf.get(), buflen); co_yield std::span{buf.get(), len}; total += len; }