Skip to content

Conversation

GnomedDev
Copy link
Contributor

@GnomedDev GnomedDev commented Oct 11, 2024

Closes #64

This is a cleaned-up copy paste of the std implementation.

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 14, 2024
…ions, r=compiler-errors

Use `ThinVec` for PredicateObligation storage

~~I noticed while profiling clippy on a project that a large amount of time is being spent allocating `Vec`s for `PredicateObligation`, and the `Vec`s are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.~~

This PR turns all the `Vec<PredicateObligation>` into a single type alias while avoiding referring to `Vec` around it, then swaps the type over to `ThinVec<PredicateObligation>` and fixes the fallout. This also contains an implementation of `ThinVec::extract_if`, copied from `Vec::extract_if` and currently being upstreamed to mozilla/thin-vec#66.

This leads to a small (0.2-0.7%) performance gain in the latest perf run.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 16, 2024
…ions, r=compiler-errors

Use `ThinVec` for PredicateObligation storage

~~I noticed while profiling clippy on a project that a large amount of time is being spent allocating `Vec`s for `PredicateObligation`, and the `Vec`s are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.~~

This PR turns all the `Vec<PredicateObligation>` into a single type alias while avoiding referring to `Vec` around it, then swaps the type over to `ThinVec<PredicateObligation>` and fixes the fallout. This also contains an implementation of `ThinVec::extract_if`, copied from `Vec::extract_if` and currently being upstreamed to mozilla/thin-vec#66.

This leads to a small (0.2-0.7%) performance gain in the latest perf run.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 17, 2024
…ompiler-errors

Use `ThinVec` for PredicateObligation storage

~~I noticed while profiling clippy on a project that a large amount of time is being spent allocating `Vec`s for `PredicateObligation`, and the `Vec`s are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.~~

This PR turns all the `Vec<PredicateObligation>` into a single type alias while avoiding referring to `Vec` around it, then swaps the type over to `ThinVec<PredicateObligation>` and fixes the fallout. This also contains an implementation of `ThinVec::extract_if`, copied from `Vec::extract_if` and currently being upstreamed to mozilla/thin-vec#66.

This leads to a small (0.2-0.7%) performance gain in the latest perf run.
Copy link
Collaborator

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

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

This is now stable for Vec, so could we make it stable here too?

@GnomedDev
Copy link
Contributor Author

@nicoburns I've updated this to match the current implementation in std, fixed the CI failures, and removed the unstable gating. I've also disabled stacked borrows in CI as std doesn't pass it, and left a comment in the Miri CI to document this for the future.

@GnomedDev GnomedDev requested a review from nicoburns August 25, 2025 11:20
@nicoburns nicoburns merged commit faa01eb into mozilla:main Aug 25, 2025
6 checks passed
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.

Add ThinVec::extract_if to match Vec::extract_if
2 participants