aboutsummaryrefslogtreecommitdiff
path: root/reftable/block.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-03-05 13:11:16 +0100
committerJunio C Hamano <gitster@pobox.com>2024-03-05 09:10:06 -0800
commit7b8abc4d8cd428e4ce044e50f7980baacaccb761 (patch)
treec9f0ee85bfca3f477cfb9ed6751edc72a600ec8c /reftable/block.c
parente0bd13beea95fa26fa1159a26051f21237f45088 (diff)
downloadgit-7b8abc4d8cd428e4ce044e50f7980baacaccb761.tar.xz
reftable/record: use scratch buffer when decoding records
When decoding log records we need a temporary buffer to decode the reflog entry's name, mail address and message. As this buffer is local to the function we thus have to reallocate it for every single log record which we're about to decode, which is inefficient. Refactor the code such that callers need to pass in a scratch buffer, which allows us to reuse it for multiple decodes. This reduces the number of allocations when iterating through reflogs. Before: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 2,068,487 allocs, 2,068,365 frees, 305,122,946 bytes allocated After: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 1,068,485 allocs, 1,068,363 frees, 281,122,886 bytes allocated Note that this commit also drop some redundant calls to `strbuf_reset()` right before calling `decode_string()`. The latter already knows to reset the buffer, so there is no need for these. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/block.c')
-rw-r--r--reftable/block.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/reftable/block.c b/reftable/block.c
index ad9074dba6..b67300a734 100644
--- a/reftable/block.c
+++ b/reftable/block.c
@@ -332,7 +332,8 @@ int block_iter_next(struct block_iter *it, struct reftable_record *rec)
return REFTABLE_FORMAT_ERROR;
string_view_consume(&in, n);
- n = reftable_record_decode(rec, it->last_key, extra, in, it->br->hash_size);
+ n = reftable_record_decode(rec, it->last_key, extra, in, it->br->hash_size,
+ &it->scratch);
if (n < 0)
return -1;
string_view_consume(&in, n);
@@ -369,6 +370,7 @@ int block_iter_seek(struct block_iter *it, struct strbuf *want)
void block_iter_close(struct block_iter *it)
{
strbuf_release(&it->last_key);
+ strbuf_release(&it->scratch);
}
int block_reader_seek(struct block_reader *br, struct block_iter *it,