git/reftable
Patrick Steinhardt 66ed011bf7 reftable/writer: optimize allocations by using a scratch buffer
Both `writer_add_record()` and `reftable_writer_add_ref()` get executed
for every single ref record we're adding to the reftable writer. And as
both functions use a local buffer to write data, the allocations we have
to do here add up during larger transactions.

Refactor the code to use a scratch buffer part of the `reftable_writer`
itself such that we can reuse it. This signifcantly reduces the number
of allocations during large transactions, e.g. when migrating 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: 5,032,171 allocs, 5,032,122 frees, 418,792,092 bytes allocated

After 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

This also translate into a small speedup:

    Benchmark 1: migrate files:reftable (refcount = 1000000, revision = HEAD~)
      Time (mean ± σ):     827.2 ms ±  16.5 ms    [User: 689.4 ms, System: 124.9 ms]
      Range (min … max):   809.0 ms … 924.7 ms    50 runs

    Benchmark 2: migrate files:reftable (refcount = 1000000, revision = HEAD)
      Time (mean ± σ):     813.6 ms ±  11.6 ms    [User: 679.0 ms, System: 123.4 ms]
      Range (min … max):   786.7 ms … 833.5 ms    50 runs

    Summary
      migrate files:reftable (refcount = 1000000, revision = HEAD) ran
        1.02 ± 0.02 times faster than migrate files:reftable (refcount = 1000000, revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-11-21 07:59:16 +09:00
..
LICENSE
basics.c reftable: convert from `strbuf` to `reftable_buf` 2024-10-17 16:59:56 -04:00
basics.h reftable: convert from `strbuf` to `reftable_buf` 2024-10-17 16:59:56 -04:00
block.c reftable: handle trivial `reftable_buf` errors 2024-10-17 16:59:56 -04:00
block.h reftable: convert from `strbuf` to `reftable_buf` 2024-10-17 16:59:56 -04:00
blocksource.c reftable/blocksource: adapt interface name 2024-10-17 16:59:56 -04:00
blocksource.h reftable/blocksource: adapt interface name 2024-10-17 16:59:56 -04:00
constants.h reftable: make the compaction factor configurable 2024-05-13 17:02:39 -07:00
error.c reftable/error: introduce out-of-memory error code 2024-10-02 07:53:50 -07:00
iter.c reftable: handle trivial `reftable_buf` errors 2024-10-17 16:59:56 -04:00
iter.h reftable: convert from `strbuf` to `reftable_buf` 2024-10-17 16:59:56 -04:00
merged.c reftable: handle trivial allocation failures 2024-10-02 07:53:55 -07:00
merged.h reftable/merged: handle allocation failures in `merged_table_init_iter()` 2024-10-02 07:53:53 -07:00
pq.c reftable: introduce `REFTABLE_FREE_AND_NULL()` 2024-10-02 07:53:56 -07:00
pq.h reftable/pq: handle allocation failures when adding entries 2024-10-02 07:53:55 -07:00
reader.c reftable: handle trivial `reftable_buf` errors 2024-10-17 16:59:56 -04:00
reader.h Merge branch 'ps/reftable-alloc-failures' 2024-10-10 14:22:25 -07:00
record.c reftable: handle trivial `reftable_buf` errors 2024-10-17 16:59:56 -04:00
record.h reftable/record: adapt `reftable_record_key()` to handle allocation failures 2024-10-17 16:59:56 -04:00
reftable-basics.h reftable/basics: merge "publicbasics" into "basics" 2024-10-02 07:53:51 -07:00
reftable-blocksource.h
reftable-error.h reftable/error: introduce out-of-memory error code 2024-10-02 07:53:50 -07:00
reftable-iterator.h reftable/generic: adapt interface to allow reuse of iterators 2024-05-13 17:04:18 -07:00
reftable-merged.h reftable/merged: handle allocation failures in `merged_table_init_iter()` 2024-10-02 07:53:53 -07:00
reftable-reader.h reftable/reader: handle allocation failures in `reader_init_iter()` 2024-10-02 07:53:53 -07:00
reftable-record.h t/helper: inline printing of reftable records 2024-08-22 07:59:47 -07:00
reftable-stack.h Merge branch 'ps/reftable-alloc-failures' 2024-10-10 14:22:25 -07:00
reftable-writer.h Merge branch 'ps/reftable-alloc-failures' 2024-10-10 14:22:25 -07:00
stack.c reftable: handle trivial `reftable_buf` errors 2024-10-17 16:59:56 -04:00
stack.h reftable: make the compaction factor configurable 2024-05-13 17:02:39 -07:00
system.h reftable: convert from `strbuf` to `reftable_buf` 2024-10-17 16:59:56 -04:00
tree.c reftable/tree: handle allocation failures 2024-10-02 07:53:55 -07:00
tree.h reftable/tree: handle allocation failures 2024-10-02 07:53:55 -07:00
writer.c reftable/writer: optimize allocations by using a scratch buffer 2024-11-21 07:59:16 +09:00
writer.h reftable/writer: optimize allocations by using a scratch buffer 2024-11-21 07:59:16 +09:00