Skip to content

Specialize TupleWindows fold - #1134

Closed
CollinYuanjieRen wants to merge 1 commit into
rust-itertools:masterfrom
CollinYuanjieRen:codex/tuple-windows-fold
Closed

CollinYuanjieRen wants to merge 1 commit into
rust-itertools:masterfrom
CollinYuanjieRen:codex/tuple-windows-fold

Conversation

@CollinYuanjieRen

Copy link
Copy Markdown

Related to #755.

Initialize the first window once, then delegate to the inner iterator's fold. Keep the width-one no-clone path and stop immediately when initial collection fails. Add regressions for partially consumed and non-fused inputs, clone/consumer panics, and callback/iterator/window drop order against the default next loop.

Short Criterion comparison on Rust 1.95.0 / Linux aarch64, 4,096 u64 values, 20 samples with 1 s warm-up and measurement (means):

Input / window width Specialized Default loop
Slice / 1 0.454 µs 0.467 µs
Slice / 2 0.472 µs 0.478 µs
Slice / 3 0.550 µs 0.548 µs
Slice / 4 0.756 µs 0.683 µs
Two chained slices / 2 0.491 µs 1.525 µs

The chained case improves about 3.1×; flat slices mostly do not benefit, and width 4 regresses about 11% in this run.

Validation: cargo test --test specializations tuple_windows, cargo fmt --check, and warning-free Clippy for the alloc-only library and changed test/benchmark targets. Benchmark: cargo bench --bench fold_specialization -- tuple_windows --sample-size 20 --measurement-time 1 --warm-up-time 1.

@phimuemue

Copy link
Copy Markdown
Member

TupleWindows is on the way out. Can you deprecate tuple_windows (we have array_windows instead)? If you want, you can try specializing Array windows::fold.

@phimuemue phimuemue closed this Oct 16, 2026
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.

2 participants