Skip to content

Optimize IntoIter::nth on v1 - #6

Open
charliermarsh wants to merge 2 commits into
v1from
charlie/codex-v1-iterator
Open

Optimize IntoIter::nth on v1#6
charliermarsh wants to merge 2 commits into
v1from
charlie/codex-v1-iterator

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

Implement IntoIter::nth by advancing past the skipped prefix once and dropping that prefix as a slice. This avoids visiting each skipped element when the type has no destructor, while still cleaning up the skipped range if a destructor panics.

Across five native Rust benchmark pairs on x86_64 Linux, nth took 16–17% less time at the inline-capacity boundary and 63–66% less for 4,096 u64 elements. Small inline cases were roughly unchanged. Some unchanged controls were sensitive to binary layout, so these results support the boundary and spilled cases rather than a general iterator speedup.

The added native benchmarks were removed in a follow-up commit and remain in the PR history.

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.

1 participant