From 7b8abc4d8cd428e4ce044e50f7980baacaccb761 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 5 Mar 2024 13:11:16 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- reftable/block.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'reftable/block.c') 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, -- cgit v1.3-5-g9baa