Compact retained elements directly in dedup_by - #5
Open
charliermarsh wants to merge 2 commits into
Open
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
Move each surviving element directly into the next hole in
dedup_by, instead of swapping the discarded payload back in the other direction. We leave the initial unique prefix in place and drop duplicates as we find them. A guard restores the untouched tail if the predicate or a destructor panics.Across three Criterion benchmark pairs on x86_64 Linux, removing adjacent duplicates took 47–54% less time for 128-byte elements across inline and spilled vectors, and about 22% less for the large
u64case. The all-equal case just beyond the inline boundary showed no consistent improvement. These benchmarks used regular inputs without destructors.The added Criterion benchmarks were removed in a follow-up commit and remain in the PR history.