diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-11-20 08:51:37 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-11-20 23:59:16 +0100 |
commit | 66ed011bf73e6503059a44698f83fd8a6b0f7726 (patch) | |
tree | 6f660d94d8b93998f6685ab90fcfc0bb7cbd9004 /reftable/writer.h | |
parent | refs: don't normalize log messages with `REF_SKIP_CREATE_REFLOG` (diff) | |
download | git-66ed011bf73e6503059a44698f83fd8a6b0f7726.tar.xz git-66ed011bf73e6503059a44698f83fd8a6b0f7726.zip |
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>
Diffstat (limited to 'reftable/writer.h')
-rw-r--r-- | reftable/writer.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/reftable/writer.h b/reftable/writer.h index e8a6fbb785..421a897dcc 100644 --- a/reftable/writer.h +++ b/reftable/writer.h @@ -20,6 +20,7 @@ struct reftable_writer { void *write_arg; int pending_padding; struct reftable_buf last_key; + struct reftable_buf buf; /* offset of next block to write. */ uint64_t next; |