Skip to content

Optimize immutable vector iterator#3571

Open
Yu-zh wants to merge 1 commit intomainfrom
codex/vector-iter-direct
Open

Optimize immutable vector iterator#3571
Yu-zh wants to merge 1 commit intomainfrom
codex/vector-iter-direct

Conversation

@Yu-zh
Copy link
Copy Markdown
Collaborator

@Yu-zh Yu-zh commented May 10, 2026

Summary

  • avoid composing vector iteration through Tree::iter, FixedArray::iter, and Iter::concat
  • implement Vector::iter as a single state machine over the tree prefix and tail
  • add focused vector iteration benchmarks

Benchmarks

Native backend, n=100000:

case before after speedup
iter().fold 1.34 ms 723.81 us 1.85x
iter().each 1.33 ms 717.15 us 1.85x
iter().to_array 1.36 ms 785.01 us 1.73x
for x in vector 1.33 ms 726.79 us 1.83x

Validation

  • moon test immut/vector --target all --target-dir /tmp/core-vector-iter-test
  • moon check immut/vector --target all --target-dir /tmp/core-vector-iter-check
  • moon bench --package immut/vector --file vector_iter_bench_test.mbt --target native --target-dir /tmp/core-vector-iter-bench-before
  • moon bench --package immut/vector --file vector_iter_bench_test.mbt --target native --target-dir /tmp/core-vector-iter-bench-after2
  • moon fmt
  • moon info
  • git diff --check

@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 4288

Coverage increased (+0.001%) to 94.648%

Details

  • Coverage increased (+0.001%) from the base build.
  • Patch coverage: 18 of 18 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15733
Covered Lines: 14891
Line Coverage: 94.65%
Coverage Strength: 218117.47 hits per line

💛 - Coveralls

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