]> git.ipfire.org Git - thirdparty/git.git/commit
reftable/block: optimize allocations by using scratch buffer
authorPatrick Steinhardt <ps@pks.im>
Wed, 20 Nov 2024 07:51:39 +0000 (08:51 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Nov 2024 22:59:17 +0000 (07:59 +0900)
commitd94ac23d3b9e223c6cacfdab7047d3d4efae3218
treebd83198005a1b65c50d08d8ec94857b05eb0583c
parentaa248b8ab2ec0dd6e22373b504cfd4ec4b9b970a
reftable/block: optimize allocations by using scratch buffer

The block writer needs to compute the key for every record that one adds
to the writer. The buffer for this key is stored on the stack and thus
reallocated on every call to `block_writer_add()`, which is inefficient.

Refactor the code so that we store the buffer in the `block_writer`
struct itself so that we can reuse it. This reduces the number of
allocations when writing many refs, e.g. when migrating one million refs
from the "files" backend to the "reftable backend. Before this change:

    HEAP SUMMARY:
        in use at exit: 80,048 bytes in 49 blocks
      total heap usage: 3,025,864 allocs, 3,025,815 frees, 372,746,291 bytes allocated

After this change:

    HEAP SUMMARY:
        in use at exit: 80,048 bytes in 49 blocks
      total heap usage: 2,013,250 allocs, 2,013,201 frees, 347,543,583 bytes allocated

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/block.c
reftable/block.h