-
Notifications
You must be signed in to change notification settings - Fork 13.3k
split ParamEnv::caller_bounds
into multiple fields
#139576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replace the `caller_bounds` function of `ParamEnv` with `ClauseKind`-specific accessors (i.e. `trait_clauses`, `region_outlives_clauses`) which will make it easier to later change the internals of `ParamEnv`.
Adding multiple fields to `ParamEnv` will grow the type, which will negatively impact performance, and it is widely assumed that `ParamEnv` is `Copy` - intern it prior to adding the additional fields.
Instead of filtering on `caller_bounds` at every use, instead filter them once when creating the `ParamEnv`. This will avoid unnecessary iteration over irrelevant bounds and improve performance.
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred in compiler/rustc_sanitizers cc @rcvalle Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_monomorphize/src/partitioning/autodiff.rs cc @ZuseZ4 Some changes occurred to the CTFE machinery Some changes occurred in cc @BoxyUwU HIR ty lowering was modified cc @fmease |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…r=<try> split `ParamEnv::caller_bounds` into multiple fields This patch splits `ParamEnv::caller_bounds` into multiple fields, one for each `ClauseKind`. This is intended to be a performance optimisation, avoiding unnecessary iteration over large `ParamEnv`s when most kinds of clauses aren't relevant in any given context. I make this change in three steps (reflected in the commits): 1. Changing the interface of `ParamEnv` - Replace `ParamEnv::caller_bounds` with functions returning iterators over specific kinds of clause, and then updating all users. A `ParamEnv::all_clauses` function, identical in behaviour to `ParamEnv::caller_bounds` remains for the handful of cases where iteration over all clauses is desirable. 2. Interning `ParamEnv` - In anticipation of changing the internals of `ParamEnv`, to avoid the type growing and to keep it `Copy`, `ParamEnv` is interned, becoming a pointer to `ParamEnvInner`. 3. Changing the internals of `ParamEnv` - Replacing the `caller_bounds` field with a field for each type of clause and updating the creation of `ParamEnv` to partition a sequence of `Clause`s into the appropriate fields. This is intended to help improve the performance of rust-lang#137944, which results in many new predicates in the `ParamEnv`, and in particular, lots of new host effect predicates which can't be fast-path'd away. As part of that work, I've experimented with variations on this patch which had worse performance: - Uninterned `ParamEnv` - `Box<[Clause<'tcx>]>` fields rather than `Clauses<'tcx>` - Box<[SpecificPredicateType<'tcx>]>` fields rather than `Clauses<'tcx>` r? types
tcx.mk_param_env(ParamEnvInner { | ||
trait_clauses: ListWithCachedTypeInfo::empty(), | ||
region_outlives_clauses: ListWithCachedTypeInfo::empty(), | ||
type_outlives_clauses: ListWithCachedTypeInfo::empty(), | ||
projection_clauses: ListWithCachedTypeInfo::empty(), | ||
const_arg_has_type_clauses: ListWithCachedTypeInfo::empty(), | ||
well_formed_clauses: ListWithCachedTypeInfo::empty(), | ||
const_evaluatable_clauses: ListWithCachedTypeInfo::empty(), | ||
host_effect_clauses: ListWithCachedTypeInfo::empty(), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe cache this in tcx
? Or would it be possible to put it in a static and insert this static in the param env interner such that you don't need to pass tcx
around in many cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at doing this locally and it has negligible performance impact as far as I can measure, so I think this would only be worth doing if we wanted to avoid passing tcx
in.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (c8e16ec): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 1.2%, secondary 1.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 1.1%, secondary 0.5%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 778.182s -> 781.865s (0.47%) |
Interesting, a version of this patch helped with #137944 so I wonder why it's not great on its own (or if I've done something different when extracting this from that patch). |
Local perf runs likely were run without incremental key hash verification, which is like 2/3rd of the regression here |
Benchmarked this with #137944 and it didn't help there either, so closing. |
This patch splits
ParamEnv::caller_bounds
into multiple fields, one for eachClauseKind
. This is intended to be a performance optimisation, avoiding unnecessary iteration over largeParamEnv
s when most kinds of clauses aren't relevant in any given context.I make this change in three steps (reflected in the commits):
ParamEnv
ParamEnv::caller_bounds
with functions returning iterators over specific kinds of clause, and then updating all users. AParamEnv::all_clauses
function, identical in behaviour toParamEnv::caller_bounds
remains for the handful of cases where iteration over all clauses is desirable.ParamEnv
ParamEnv
, to avoid the type growing and to keep itCopy
,ParamEnv
is interned, becoming a pointer toParamEnvInner
.ParamEnv
caller_bounds
field with a field for each type of clause and updating the creation ofParamEnv
to partition a sequence ofClause
s into the appropriate fields.This is intended to help improve the performance of #137944, which results in many new predicates in the
ParamEnv
, and in particular, lots of new host effect predicates which can't be fast-path'd away. As part of that work, I've experimented with variations on this patch which had worse performance:ParamEnv
Box<[Clause<'tcx>]>
fields rather thanClauses<'tcx>
fields rather than
Clauses<'tcx>`r? types