aboutsummaryrefslogtreecommitdiff
path: root/reftable/reader.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-04-08 14:17:04 +0200
committerJunio C Hamano <gitster@pobox.com>2024-04-15 10:36:09 -0700
commitce1f213cc91cf545736048f28117fe1de89b8134 (patch)
tree3e8401f9a1682045caa99e8e94211da7f9716eab /reftable/reader.c
parent15a60b747e4f0e0d11353f8e89bc9ce7b36c5512 (diff)
downloadgit-ce1f213cc91cf545736048f28117fe1de89b8134.tar.xz
reftable/block: reuse `zstream` state on inflation
When calling `inflateInit()` and `inflate()`, the zlib library will allocate several data structures for the underlying `zstream` to keep track of various information. Thus, when inflating repeatedly, it is possible to optimize memory allocation patterns by reusing the `zstream` and then calling `inflateReset()` on it to prepare it for the next chunk of data to inflate. This is exactly what the reftable code is doing: when iterating through reflogs we need to potentially inflate many log blocks, but we discard the `zstream` every single time. Instead, as we reuse the `block_reader` for each of the blocks anyway, we can initialize the `zstream` once and then reuse it for subsequent inflations. Refactor the code to do so, which leads to a significant reduction in the number of allocations. The following measurements were done when iterating through 1 million reflog entries. Before: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 23,028 allocs, 22,906 frees, 162,813,552 bytes allocated After: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 302 allocs, 180 frees, 88,352 bytes allocated Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/reader.c')
-rw-r--r--reftable/reader.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/reftable/reader.c b/reftable/reader.c
index aacd5f1337..481dff10d4 100644
--- a/reftable/reader.c
+++ b/reftable/reader.c
@@ -459,6 +459,7 @@ static int reader_seek_linear(struct table_iter *ti,
* we would not do a linear search there anymore.
*/
memset(&next.br.block, 0, sizeof(next.br.block));
+ next.br.zstream = NULL;
next.br.uncompressed_data = NULL;
next.br.uncompressed_cap = 0;