Skip to content

Specialize KMergeBy fold for the final input iterator - #1133

Open
CollinYuanjieRen wants to merge 1 commit into
rust-itertools:masterfrom
CollinYuanjieRen:codex/kmerge-fold
Open

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

Conversation

@CollinYuanjieRen

Copy link
Copy Markdown

Specialize KMergeBy::fold once only one input remains, while retaining the existing next path for multiple inputs. A pending element preserves advancing the tail before consuming the previous head.

Adds event-order regressions (including non-fused iterators and partial consumption) and single, skewed, and balanced benchmarks. In a Linux aarch64 / Rust 1.95.0 sample with 4096 elements, specialized vs. unspecialized means were approximately 0.534 vs. 6.919 µs (single), 0.608 vs. 6.946 µs (skewed), and 9.795 vs. 9.857 µs (balanced).

Part of #755.

Validated the kmerge specialization tests and Clippy for the affected tests/benchmark and the alloc-only library configuration.

@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.66%. Comparing base (6814180) to head (2c510fb).
⚠️ Report is 223 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1133      +/-   ##
==========================================
- Coverage   94.38%   93.66%   -0.73%     
==========================================
  Files          48       52       +4     
  Lines        6665     6503     -162     
==========================================
- Hits         6291     6091     -200     
- Misses        374      412      +38     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/kmerge_impl.rs
Comment on lines +238 to +239
let (acc, last) = tail.fold((acc, head), |(acc, head), next| (f(acc, head), next));
f(acc, last)

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 hope I don't miss the forest for the trees, but counldn't this

  • first call f(acc, head),
  • then call tail.fold(acc, f)?

This branch has not been deployed

No deployments
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