Skip to content

Improve ZeroVec sum performance - #8732

Merged
Manishearth merged 2 commits into
unicode-org:mainfrom
wozhenbang2004:patch-1
Nov 19, 2026
Merged

Manishearth merged 2 commits into
unicode-org:mainfrom
wozhenbang2004:patch-1

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Fixes #6562.

Forward ZeroSliceIter::fold through the underlying slice iterator. With Rust 1.98.0 on x86_64, the existing zerovec_serde/sum/stress/zerovec benchmark now uses a vectorized reduction; the original binary emitted a scalar loop.

Using the checked-in benchmark and bench profile, two runs per binary in A/B/B/A order gave these Criterion slope estimates:

Benchmark Before After
sum/stress/zerovec 37.15–38.39 ns 7.49–8.06 ns
sum/stress/vec (control) 6.53–6.97 ns 9.61–11.33 ns

The Vec control's loop instructions are byte-identical, but its placement and timings changed. These measurements are specific to this benchmark and setup.

Tests cover empty and forward/reverse folds, plus folding after taking elements from both ends. cargo test -p zerovec --all-features and cargo clippy -p zerovec --all-features --all-targets -- -D warnings pass.

Changelog

zerovec: Improve summation performance for ZeroSliceIter.

Comment thread utils/zerovec/src/zerovec/slice.rs Resolved

@sffc sffc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wish Rust had a better way to delegate impls. Adding one-off overrides to fns that are motivated by benchmarks seems fine.

@sffc

sffc commented Nov 19, 2026

Copy link
Copy Markdown
Member

Thank you for the contribution!

@Manishearth

Copy link
Copy Markdown
Member

I wish Rust had a better way to delegate impls

I mean the default is delegation, this is just delegating in a way that is not the best.

@Manishearth
Manishearth merged commit a240427 into unicode-org:main Nov 19, 2026
34 checks passed
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.

Investigate performance drop in ZeroVec sum()

3 participants