Skip to content

perf(alp): avoid per-combination allocations when searching exponents - #8565

Merged
AdamGS merged 2 commits into
vortex-data:developfrom
miniex:perf/alp-exponent-sampling
Jun 24, 2026
Merged

AdamGS merged 2 commits into
vortex-data:developfrom
miniex:perf/alp-exponent-sampling

Conversation

@miniex

@miniex miniex commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

find_best_exponents ran a full encode for every (e, f) candidate just to size the result, allocating the encoded, patch and chunk-offset buffers across the whole e/f search space. It now estimates the size in a single allocation-free pass via estimate_encoded_size_for_exponents, which reproduces the existing estimate_encoded_size exactly, so the chosen exponents (and therefore the compressed output) are bit-for-bit unchanged.

This is the throughput half of #919; the two-level stratified sampling / top-N reuse the issue describes would change which exponents are picked and depends on per-column scheme state (#8434), so I left it out here.

Benchmark

encodings/alp/benches/alp_compress.rs, compress medians (type, length, patch-fraction, valid-fraction):

case before after speedup
f64 (1000, 0.0, 1.0) 39.1 us 14.0 us 2.8x
f64 (1000, 0.1, 0.25) 45.0 us 16.5 us 2.7x
f32 (1000, 0.0, 1.0) 14.6 us 5.8 us 2.5x
f64 (10000, 0.0, 1.0) 53.1 us 28.6 us 1.9x
f64 (10000, 0.1, 0.25) 73.7 us 49.4 us 1.5x

Testing

cargo nextest run -p vortex-alp -p vortex-btrblocks passes, including a new equivalence test (estimate_for_exponents_matches_full_encode) that asserts the allocation-free estimate equals a full encode + estimate_encoded_size for every candidate exponent across kept, patched and all-patched inputs. fmt + clippy --all-targets --all-features + cargo doc clean.


I'm Korean, so sorry if any wording reads a little awkward.

`find_best_exponents` ran a full `encode` for every `(e, f)` candidate just to
size the result. it now estimates the size in a single allocation-free pass over
the sample, leaving the chosen exponents (and the compression) unchanged.

Relates to vortex-data#919

Signed-off-by: Han Damin <[email protected]>
@miniex
miniex requested a review from a team June 24, 2026 04:44
@codspeed

codspeed Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 76.45%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 39 improved benchmarks
❌ 3 regressed benchmarks
✅ 1543 untouched benchmarks
⏩ 4 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation slice_empty_vortex 310 ns 368.3 ns -15.84%
❌ Simulation encode_varbin[(1000, 8)] 141.1 µs 157 µs -10.14%
❌ Simulation encode_varbin[(1000, 4)] 140.5 µs 156.1 µs -10.03%
⚡ Simulation compress_alp[f64, (1000, 0.0, 1.0)] 237.2 µs 73.3 µs ×3.2
⚡ Simulation compress_alp[f64, (1000, 0.0, 0.95)] 242.5 µs 78.6 µs ×3.1
⚡ Simulation compress_alp[f64, (1000, 0.0, 0.25)] 242.5 µs 78.7 µs ×3.1
⚡ Simulation compress_alp[f64, (1000, 0.01, 1.0)] 284.7 µs 95.1 µs ×3
⚡ Simulation compress_alp[f64, (1000, 0.1, 1.0)] 286.1 µs 96.8 µs ×3
⚡ Simulation compress_alp[f64, (1000, 0.01, 0.95)] 290.6 µs 101.1 µs ×2.9
⚡ Simulation compress_alp[f64, (1000, 0.01, 0.25)] 290.1 µs 100.9 µs ×2.9
⚡ Simulation compress_alp[f64, (1000, 0.1, 0.25)] 293.5 µs 104.3 µs ×2.8
⚡ Simulation compress_alp[f64, (1000, 0.1, 0.95)] 297.4 µs 108.8 µs ×2.7
⚡ Simulation compress_alp[f32, (1000, 0.0, 1.0)] 87.9 µs 33.8 µs ×2.6
⚡ Simulation compress_alp[f32, (1000, 0.0, 0.95)] 93 µs 39.1 µs ×2.4
⚡ Simulation compress_alp[f32, (1000, 0.0, 0.25)] 93.5 µs 39.6 µs ×2.4
⚡ Simulation compress_alp[f32, (1000, 0.01, 1.0)] 118.2 µs 56.2 µs ×2.1
⚡ Simulation compress_alp[f32, (1000, 0.1, 1.0)] 119.5 µs 57.9 µs ×2.1
⚡ Simulation compress_alp[f32, (1000, 0.01, 0.25)] 124.2 µs 62.5 µs +98.52%
⚡ Simulation compress_alp[f32, (1000, 0.01, 0.95)] 123.8 µs 62.6 µs +97.78%
⚡ Simulation compress_alp[f32, (1000, 0.1, 0.25)] 127.7 µs 65.6 µs +94.57%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

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


Comparing miniex:perf/alp-exponent-sampling (88c7c53) with develop (f41dc23)

Open in CodSpeed

Footnotes

  1. 4 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. ↩

@AdamGS AdamGS added the changelog/performance A performance improvement label Jun 24, 2026
@AdamGS AdamGS self-assigned this Jun 24, 2026
Comment thread encodings/alp/src/alp/mod.rs Resolved
@AdamGS

AdamGS commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

very cool optimization! just one ask

fold the four kept/all min/max options into two `Option<(min, max)>` and a
shared `update_bounds` helper, since both bounds widen with the same fallback.
document what the `kept` and `all` ranges mean. no behavior change; the size
estimate is bit-for-bit unchanged.

Signed-off-by: Han Damin <[email protected]>
@miniex
miniex requested a review from AdamGS June 24, 2026 11:29

@AdamGS AdamGS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution! great improvement.

@AdamGS
AdamGS merged commit 4457a4a into vortex-data:develop Jun 24, 2026
75 of 78 checks passed
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