Perf: Clear the param env for more global trait goals - #161126
Open
Dandandan wants to merge 1 commit into
Open
Conversation
The branch in `evaluate_trait_predicate_recursively` that clears the param env, so a global goal can be cached globally, rarely fires: - it asks `obligation.is_global()`, but an `Obligation` visits its own `param_env`, so that is false whenever the env holds anything local -- including the region inference variables the branch then discards. It could only fire when the env was already empty. - it requires every bound to mention a generic parameter. An outlives bound is never a selection candidate, so it cannot change the answer either. Code using `#[async_trait]` runs into this: every method carries `where 'life0: 'async_trait, ..`, whose bounds hold region inference variables, so each method re-proves the same `Send`/`Sync` goals.
Dandandan
force-pushed
the
clear-param-env-for-global-goals
branch
from
August 15, 2026 09:23
892ca2d to
2850f83
Compare
Dandandan
marked this pull request as ready for review
August 15, 2026 09:47
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @petrochenkov (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
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.
evaluate_trait_predicate_recursivelyclears the param env when its bounds cannotaffect a global goal, so the result can go in the global cache. It almost never
fires today, for two reasons:
It asks
obligation.is_global(). AnObligationvisits its ownparam_env, sothis is false whenever the env holds anything local, including the region
inference variables the branch is about to discard. In practice it could only
fire when the env was already empty.
It requires every bound to mention a generic parameter. An outlives bound is
never a selection candidate, so it cannot change the answer either.
Code using
#[async_trait]runs into this. Every method there carrieswhere 'life0: 'async_trait, .., and those bounds hold region inferencevariables, so each method re-proves the same
Send/Syncgoals from scratch.On a generated test file with an
async_trait-shaped trait over a large concretetype graph,
evaluate_obligationself time drops:I found this while looking at compile times in DataFusion, where a few crates
spend most of their time proving
Sendfor futures returned by#[async_trait]methods.
AI Disclosure
I used LLM (Claude) to run some experiments and change the code