Skip to content

Speed up sparse takes from chunked Dict arrays - #11548

Merged
joseph-isaacs merged 3 commits into
developfrom
ji/alp-rd-take-chunked-bench
Nov 17, 2026
Merged

joseph-isaacs merged 3 commits into
developfrom
ji/alp-rd-take-chunked-bench

Conversation

@joseph-isaacs

@joseph-isaacs joseph-isaacs commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Dict::append_to_builder decoded every value of an encoded Dict before gathering. Taking a few rows from each segment of a chunked ALP-RD column therefore decoded every segment in full, which was 77% of a vector re-rank query. Fixed-width Dicts now run the values' take kernel when there are at most 1/16 as many codes as values, which is the break-even measured on ALP-RD. Utf8/Binary keep their existing ratio of 4.

Measured against the new alp_rd_take_chunked benchmark in #11545, CodSpeed shows ×5.3 for one primitive row per segment and ×2.7 for one FixedSizeList vector. #11545 was stacked on this PR and has been merged into it, so this PR now contains both the benchmark and the change.

🤖 Generated with Claude Code

…array

`array.take(indices)` on an encoded array is a lazy `Dict` whose values are
the whole encoded array. When such a Dict is a chunk of a ChunkedArray,
canonicalizing appends it to a builder through `Dict::append_to_builder`.

`alp_rd_take_chunked` measures that path. It takes rows from each of four
ALP-RD f32 segments of 262,144 values (right bit width 24, about 2,000
left-part patches), chunks the results and canonicalizes them recursively,
as a primitive column and as FixedSizeList<f32, 64>.

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UeniBE6jGwH9sRoqTmLZFz
@codspeed

codspeed Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 16.4%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

❌ 1 regressed benchmark
✅ 1964 untouched benchmarks
🆕 4 new benchmarks
⏩ 53 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation compare[1] 47.3 µs 56.5 µs -16.4%
🆕 CPU Simulation fixed_size_list[1] N/A 366.1 µs N/A
🆕 CPU Simulation fixed_size_list[16] N/A 538.3 µs N/A
🆕 CPU Simulation primitive[1] N/A 163.1 µs N/A
🆕 CPU Simulation primitive[16] N/A 193.7 µs N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ji/alp-rd-take-chunked-bench (87f0363) with develop (3111483)

Open in CodSpeed

Footnotes

  1. 53 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

)

## Summary

`array.take(indices)` on an encoded array is a lazy `Dict` whose values
are the whole encoded array. Executing that `Dict` directly is fine,
because the values' take kernel runs as an execute-parent kernel. But
when the `Dict` sits inside a `ChunkedArray`, canonicalizing appends
each chunk to a builder, and `Dict::append_to_builder` decoded **every**
value before gathering.

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
@joseph-isaacs joseph-isaacs added the changelog/performance A performance improvement label Nov 17, 2026
@joseph-isaacs
joseph-isaacs enabled auto-merge (squash) November 17, 2026 16:59
`test_counts_file_covers_every_discovered_target` requires every benchmark
target in `scripts/codspeed_bench_counts.json`. Under CodSpeed,
`alp_rd_take_chunked` runs 4 benchmarks.

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UeniBE6jGwH9sRoqTmLZFz
joseph-isaacs added a commit that referenced this pull request Nov 17, 2026
Fold it into the Pull Requests section that develop added, and add what
landing #11548 and #11545 showed: the benchmark PR must also count its
benchmarks in `scripts/codspeed_bench_counts.json`, and merging the stacked
change while its base is still the benchmark branch folds it into the
benchmark PR.

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UeniBE6jGwH9sRoqTmLZFz
@joseph-isaacs joseph-isaacs changed the title Add a benchmark taking few rows of ALP-RD segments through a chunked array Speed up sparse takes from chunked Dict arrays Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Benchmark results for the change, which came in from #11545.

CodSpeed simulation (#11545 compared with this branch before the change):

benchmark before after change
primitive[1] 864.1 µs 163.1 µs ×5.3
primitive[16] 865.3 µs 193.8 µs ×4.5
fixed_size_list[1] 979.6 µs 366.0 µs ×2.7
fixed_size_list[16] 983.6 µs 538.3 µs +83%

Local walltime (4 ALP-RD f32 segments of 262,144 values; median):

rows taken per segment before after
FSL: 1 vector 830 µs 27 µs
FSL: 16 835 µs 94 µs
FSL: 256 (1/16 of the values) 947 µs 600–740 µs
FSL: 1024 / 2048 same path same path
primitive: 1 ~800 µs 13 µs
primitive: 2048 ~800 µs 125 µs

The threshold is 1/16 because taking costs about 13 ns per row, against about 0.8 ns per value to decode everything, so the two break even at about one row in eleven. With a 1/4 threshold, taking 1/4 of the rows was 2.3× slower than decoding everything.

The other CodSpeed regressions are in code this PR doesn't touch: bitpack_compare_sweep::compare[1] on this PR, and the walltime decode_bitpacked_chunked_avx512 on #11545. I ran every CPU benchmark crate once with a marker on the changed branch, and only alp_rd_take_chunked reached it.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

The failing CodSpeed check (bitpack_compare_sweep::u8::compare[1], −16.4%) isn't caused by this PR:

  • The same regression, −16.24%, was already reported on 6a5c3c4, the benchmark-only commit. That commit adds only encodings/alp/benches/alp_rd_take_chunked.rs and touches no library code.
  • The fix in this PR changes only the sparse-take branch of Dict::append_to_builder. I ran every vortex-fastlanes benchmark once in test mode with a marker on that branch, and none of them reached it.

The fastlanes compare benchmark therefore runs the same code with and without this PR. The regression can be acknowledged on CodSpeed.


Generated by Claude Code

@joseph-isaacs
joseph-isaacs merged commit 125782a into develop Nov 17, 2026
77 of 78 checks passed
@joseph-isaacs
joseph-isaacs deleted the ji/alp-rd-take-chunked-bench branch November 17, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/performance A performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants