On Wed, Dec 20, 2023 at 10:17:17AM +0100, Patrick Steinhardt wrote: > When reading ref records of type "val1" we store its object ID in an > allocated array. This results in an additional allocation for every > single ref record we read, which is rather inefficient especially when > iterating over refs. > > Refactor the code to instead use a static array of `GIT_MAX_RAWSZ` > bytes. While this means that `struct ref_record` is bigger now, we > typically do not store all refs in an array anyway and instead only > handle a limited number of records at the same point in time. > > Using `git show-ref --quiet` in a repository with ~350k refs this leads > to a significant drop in allocations. Before: > > HEAP SUMMARY: > in use at exit: 21,098 bytes in 192 blocks > total heap usage: 2,116,683 allocs, 2,116,491 frees, 76,098,060 bytes allocated > > After: > > HEAP SUMMARY: > in use at exit: 21,098 bytes in 192 blocks > total heap usage: 1,419,031 allocs, 1,418,839 frees, 62,145,036 bytes allocated > > Signed-off-by: Patrick Steinhardt <ps@xxxxxx> I screwed up the rebase. The following diff is required on top: diff --git a/reftable/readwrite_test.c b/reftable/readwrite_test.c index 56c0b4db5d..87b238105c 100644 --- a/reftable/readwrite_test.c +++ b/reftable/readwrite_test.c @@ -809,11 +809,10 @@ static void test_write_multiple_indices(void) writer = reftable_new_writer(&strbuf_add_void, &writer_buf, &opts); reftable_writer_set_limits(writer, 1, 1); for (i = 0; i < 100; i++) { - unsigned char hash[GIT_SHA1_RAWSZ] = {i}; struct reftable_ref_record ref = { .update_index = 1, .value_type = REFTABLE_REF_VAL1, - .value.val1 = hash, + .value.val1 = {i}, }; strbuf_reset(&buf); Will fix in v2 of this series. Patrick
Attachment:
signature.asc
Description: PGP signature