summaryrefslogtreecommitdiffstats
path: root/reftable/block.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-04-08 14:24:35 +0200
committerJunio C Hamano <gitster@pobox.com>2024-04-09 02:01:42 +0200
commita155ab2bf4e16b8fe1e0644d9d57d2c62eecd452 (patch)
tree92df875b5d1038d64f149f70d12259ac459eeb72 /reftable/block.h
parentreftable/writer: reset `last_key` instead of releasing it (diff)
downloadgit-a155ab2bf4e16b8fe1e0644d9d57d2c62eecd452.tar.xz
git-a155ab2bf4e16b8fe1e0644d9d57d2c62eecd452.zip
reftable/block: reuse zstream when writing log blocks
While most reftable blocks are written to disk as-is, blocks for log records are compressed with zlib. To compress them we use `compress2()`, which is a simple wrapper around the more complex `zstream` interface that would require multiple function invocations. One downside of this interface is that `compress2()` will reallocate internal state of the `zstream` interface on every single invocation. Consequently, as we call `compress2()` for every single log block which we are about to write, this can lead to quite some memory allocation churn. Refactor the code so that the block writer reuses a `zstream`. This significantly reduces the number of bytes allocated when writing many refs in a single transaction, as demonstrated by the following benchmark that writes 100k refs in a single transaction. Before: HEAP SUMMARY: in use at exit: 671,931 bytes in 151 blocks total heap usage: 22,631,887 allocs, 22,631,736 frees, 1,854,670,793 bytes allocated After: HEAP SUMMARY: in use at exit: 671,931 bytes in 151 blocks total heap usage: 22,620,528 allocs, 22,620,377 frees, 1,245,549,984 bytes allocated Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/block.h')
-rw-r--r--reftable/block.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/reftable/block.h b/reftable/block.h
index 47acc62c0a..1375957fc8 100644
--- a/reftable/block.h
+++ b/reftable/block.h
@@ -18,6 +18,7 @@ https://developers.google.com/open-source/licenses/bsd
* allocation overhead.
*/
struct block_writer {
+ z_stream *zstream;
uint8_t *buf;
uint32_t block_size;