Skip to content

perf: reuse key/arg scratch buffers in hash aggregation (#674) - #676

Open
iheitlager wants to merge 1 commit into
mainfrom
fix/674-hash-agg-scratch-buffers
Open

perf: reuse key/arg scratch buffers in hash aggregation (#674)#676
iheitlager wants to merge 1 commit into
mainfrom
fix/674-hash-agg-scratch-buffers

Conversation

@iheitlager

Copy link
Copy Markdown
Member

Summary

  • hash_agg_find (src/vdbe/hash_agg.rs:268) no longer allocates a fresh Vec<u8> key buffer / Vec<Value> key-values buffer per row — it reuses HashAggState-held scratch buffers via take/give-back, cloning into GroupSlot/the index HashMap only when a row starts a new group.
  • hash_agg_step (src/vdbe/hash_agg.rs:340) reuses a scratch Vec<Value> for per-row aggregate arguments instead of allocating fresh each row; arguments are only read by reference so no clone is needed at all.
  • read_group_by_agg improves from ~2.5x oracle to ~2.26x oracle on bench_1mb.db.

Test plan

  • cargo test --lib hash_agg (13 tests, all pass, unmodified)
  • cargo test (full suite, 979+ tests, all pass)
  • cargo clippy --lib --all-targets clean
  • cargo bench --bench crud -- read_group_by_agg shows improvement (4.87ms → oracle 2.16ms, was 2.5x, now ~2.26x)

spend: matched estimate

Closes #674

hash_agg_find allocated a fresh Vec<u8> key buffer and Vec<Value> for
key values on every row, and hash_agg_step allocated a fresh Vec<Value>
for arguments every row. Reuse HashAggState-held scratch buffers via
take/give-back instead: cleared and refilled per row, with clones only
on the group-creation path (once per distinct group) rather than per
row. Reduces read_group_by_agg from ~2.5x to ~2.26x oracle.

spend: matched estimate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: reuse key/arg scratch buffers in hash aggregation (hash_agg.rs)

1 participant