reftable/record: reuse message when decoding log records
Same as the preceding commit we can allocate log messages as needed when decoding log records, thus further reducing the number of allocations. Before: 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 After: 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 Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Mar 5, 2024 at 13:11 UTC
e0bd13beea95fa26fa1159a26051f21237f45088
2 files changed
+4
-2
reftable/record.c
+3
-2
@@ -871,6 +871,7 @@ static int reftable_log_record_decode(void *rec, struct strbuf key,
871
switch (r->value_type) {
872
case REFTABLE_LOG_UPDATE:
873
FREE_AND_NULL(r->value.update.message);
874
+ r->value.update.message_cap = 0;
875
FREE_AND_NULL(r->value.update.email);
876
FREE_AND_NULL(r->value.update.name);
877
break;
@@ -943,8 +944,8 @@ static int reftable_log_record_decode(void *rec, struct strbuf key,
944
goto done;
945
string_view_consume(&in, n);
946
946
- r->value.update.message =
947
- reftable_realloc(r->value.update.message, dest.len + 1);
947
+ REFTABLE_ALLOC_GROW(r->value.update.message, dest.len + 1,
948
+ r->value.update.message_cap);
949
memcpy(r->value.update.message, dest.buf, dest.len);
950
r->value.update.message[dest.len] = 0;
951
reftable/reftable-record.h
+1
@@ -96,6 +96,7 @@ struct reftable_log_record {
96
uint64_t time;
97
int16_t tz_offset;
98
char *message;
99
+ size_t message_cap;
100
} update;
101
} value;
102
};