git/reftable
Patrick Steinhardt 92fa3253c8 reftable/block: swap buffers instead of copying
When iterating towards the next record in a reftable block we need to
keep track of the key that the last record had. This is required because
reftable records use prefix compression, where subsequent records may
reuse parts of their preceding record's key.

This key is stored in the `block_iter::last_key`, which we update after
every call to `block_iter_next()`: we simply reset the buffer and then
add the current key to it.

This is a bit inefficient though because it requires us to copy over the
key on every iteration, which adds up when iterating over many records.
Instead, we can make use of the fact that the `block_iter::key` buffer
is basically only a scratch buffer. So instead of copying over contents,
we can just swap both buffers.

The following benchmark prints a single ref matching a specific pattern
out of 1 million refs via git-show-ref(1):

  Benchmark 1: show-ref: single matching ref (revision = HEAD~)
    Time (mean ± σ):     155.7 ms ±   5.0 ms    [User: 152.1 ms, System: 3.4 ms]
    Range (min … max):   150.8 ms … 185.7 ms    1000 runs

  Benchmark 2: show-ref: single matching ref (revision = HEAD)
    Time (mean ± σ):     150.8 ms ±   4.2 ms    [User: 147.1 ms, System: 3.5 ms]
    Range (min … max):   145.1 ms … 180.7 ms    1000 runs

  Summary
    show-ref: single matching ref (revision = HEAD) ran
      1.03 ± 0.04 times faster than show-ref: single matching ref (revision = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-02-12 09:18:04 -08:00
..
LICENSE
basics.c
basics.h
basics_test.c
block.c reftable/block: swap buffers instead of copying 2024-02-12 09:18:04 -08:00
block.h
block_test.c reftable/record: store "val1" hashes as static arrays 2024-01-03 09:54:20 -08:00
blocksource.c reftable/blocksource: use mmap to read tables 2024-01-11 12:10:59 -08:00
blocksource.h
constants.h
dump.c
error.c
generic.c
generic.h
iter.c
iter.h
merged.c reftable/merged: skip comparison for records of the same subiter 2024-02-12 09:18:04 -08:00
merged.h reftable/merged: allocation-less dropping of shadowed records 2024-02-12 09:18:04 -08:00
merged_test.c Merge branch 'ps/reftable-fixes-and-optims' 2024-01-16 10:11:57 -08:00
pq.c reftable/pq: allocation-less comparison of entry keys 2024-02-12 09:18:04 -08:00
pq.h
pq_test.c
publicbasics.c
reader.c Merge branch 'en/header-cleanup' 2024-01-08 14:05:15 -08:00
reader.h
readwrite_test.c Merge branch 'ps/reftable-fixes-and-optims' 2024-01-16 10:11:57 -08:00
record.c reftable/record: introduce function to compare records by key 2024-02-12 09:18:04 -08:00
record.h reftable/record: introduce function to compare records by key 2024-02-12 09:18:04 -08:00
record_test.c reftable/record: store "val2" hashes as static arrays 2024-01-03 09:54:21 -08:00
refname.c
refname.h
refname_test.c
reftable-blocksource.h
reftable-error.h
reftable-generic.h
reftable-iterator.h
reftable-malloc.h
reftable-merged.h
reftable-reader.h
reftable-record.h reftable/record: store "val2" hashes as static arrays 2024-01-03 09:54:21 -08:00
reftable-stack.h
reftable-tests.h
reftable-writer.h
stack.c Merge branch 'ps/reftable-optimize-io' 2024-01-29 16:02:59 -08:00
stack.h reftable/stack: fix race in up-to-date check 2024-01-18 12:02:09 -08:00
stack_test.c Merge branch 'ps/reftable-fixes-and-optims' 2024-01-16 10:11:57 -08:00
system.h reftable/stack: fix race in up-to-date check 2024-01-18 12:02:09 -08:00
test_framework.c
test_framework.h
tree.c
tree.h
tree_test.c
writer.c reftable/writer: fix index corruption when writing multiple indices 2024-01-03 09:54:20 -08:00
writer.h