Skip to content

Commit 193fcb3

Browse files
pks-tgitster
authored andcommitted
reftable/record: reuse refnames when decoding log records
When decoding a log record we always reallocate their refname arrays. This results in quite a lot of needless allocation churn. Refactor the code to grow the array as required only. Like this, we should usually only end up reallocating the array a small handful of times when iterating over many refs. Before: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 4,068,487 allocs, 4,068,365 frees, 332,011,793 bytes allocated After: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 3,068,488 allocs, 3,068,366 frees, 307,122,961 bytes allocated Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 01639ec commit 193fcb3

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

reftable/record.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ static int reftable_log_record_decode(void *rec, struct strbuf key,
861861
if (key.len <= 9 || key.buf[key.len - 9] != 0)
862862
return REFTABLE_FORMAT_ERROR;
863863

864-
r->refname = reftable_realloc(r->refname, key.len - 8);
864+
REFTABLE_ALLOC_GROW(r->refname, key.len - 8, r->refname_cap);
865865
memcpy(r->refname, key.buf, key.len - 8);
866866
ts = get_be64(key.buf + key.len - 8);
867867

reftable/reftable-record.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ int reftable_ref_record_equal(const struct reftable_ref_record *a,
7474
/* reftable_log_record holds a reflog entry */
7575
struct reftable_log_record {
7676
char *refname;
77+
size_t refname_cap;
7778
uint64_t update_index; /* logical timestamp of a transactional update.
7879
*/
7980

0 commit comments

Comments
 (0)