Skip to content

Backport v2’s retain implementation to v1 - #596

Open
charliermarsh wants to merge 4 commits into
servo:v1from
astral-sh:charlie/codex-v1-compact
Open

Backport v2’s retain implementation to v1#596
charliermarsh wants to merge 4 commits into
servo:v1from
astral-sh:charlie/codex-v1-compact

Conversation

@charliermarsh

Copy link
Copy Markdown
Contributor

Summary

This PR applies the existing v2 compaction approach to v1's retain: leave the initial retained prefix in place, then move each survivor into the next hole instead of swapping it with a discarded element. Removed elements are dropped during the scan, and a guard restores the untouched tail if the predicate or a destructor panics.

I benchmarked this on Linux (x86), and retaining half the input took 40-60% less time for small integer vectors, 16-21% less time for 4,096 integers, and 24-38% less for 4,096 larger elements.

I included some native benchmarks but removed in a follow-up commit; you can see them in the PR history.

Comment thread tests/retain.rs Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not create a tests/retain.rs file for that, include it on src/tests.rs

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