Make insert_many fallback linear with empty and single fast paths - #10
Open
charliermarsh wants to merge 3 commits into
Open
Make insert_many fallback linear with empty and single fast paths#10charliermarsh wants to merge 3 commits into
charliermarsh wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an iterator produces more elements than its lower size hint,
insert_manyshifts the existing tail once for every extra element. We now append the excess elements and rotate them into position once, avoiding that repeated movement. Empty and single-element inputs have fast paths, and a guard puts successfully appended elements in place if iteration panics.Across five native Rust benchmark pairs on x86_64 Linux, inserting 1,024 elements before a 1,024-element tail dropped from about 90 µs to 0.65 µs. Empty and single insertions stayed around 14 ns and 21 ns, respectively; a short insertion with a weak positive size hint was about 6% slower. The large gain comes from avoiding repeated tail movement in that workload.
The added native benchmarks were removed in a follow-up commit and remain in the PR history.