-
Notifications
You must be signed in to change notification settings - Fork 13.3k
resolve: Stop creating NameBinding
s on every use, create them once per definition instead
#113408
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
r? @fee1-dead (rustbot has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit b8cb9b3f49d53db6efd3613b0a8a37bbe8b82642 with merge fb3c2f2e93d4207348fe7c62386f58b91dc6596f... |
☀️ Try build successful - checks-actions |
1 similar comment
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (fb3c2f2e93d4207348fe7c62386f58b91dc6596f): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking 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. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 656.625s -> 657.843s (0.19%) |
b8cb9b3
to
cadc7be
Compare
NameBinding
s on every use, create them once per definition instead
cc #115089 r? compiler |
d38ba0e
to
53c72df
Compare
NameBinding
s on every use, create them once per definition insteadNameBinding
s on every use, create them once per definition instead
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 53c72df6b05587af5b44d9019fef25c49f15009d with merge eebbf243e083fba445d50a681206762964d9be19... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (eebbf243e083fba445d50a681206762964d9be19): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking 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. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 634.141s -> 634.262s (0.02%) |
compiler/rustc_resolve/src/lib.rs
Outdated
} else { | ||
update_binding = true; |
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.
Could you add a comment explaining what happens here?
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.
Well, it's a micro-optimization to avoid resetting binding
to the same value when it already exists, but it's likely useless so I'll just remove it.
.extern_prelude | ||
.entry(ident.normalize_to_macros_2_0()) | ||
.or_insert(ExternPreludeEntry { binding: None, introduced_by_item: true }); | ||
entry.binding = Some(imported_binding); |
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.
What happens if binding
is already Some
?
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.
This is a case where binding from command line (--extern foo
) is replaced with a binding from extern crate foo
item in source code.
compiler/rustc_resolve/src/lib.rs
Outdated
@@ -1006,6 +1006,7 @@ pub struct Resolver<'a, 'tcx> { | |||
dummy_binding: NameBinding<'a>, | |||
builtin_types_bindings: FxHashMap<Symbol, NameBinding<'a>>, | |||
builtin_attrs_bindings: FxHashMap<Symbol, NameBinding<'a>>, | |||
crate_root_bindings: FxHashMap<Module<'a>, NameBinding<'a>>, |
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.
Could you add a comment for this field? Which name does NameBinding
correspond to?
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.
The name crate
(or $crate
), which is not explicitly declared anywhere.
Maybe it makes sense to route self
for a module through the same binding as well, but self
currently never produces NameBinding
s due to being processed through a special case in resolve_path_with_ribs
(would be nice to make it more uniform).
instead of creating a new every time a name from extern prelude is accessed
instead of creating a new every time `crate` or `$crate` is used
instead of creating them every time such attribute is used
53c72df
to
453edeb
Compare
Updated. |
Thanks! |
☀️ Test successful - checks-actions |
Finished benchmarking commit (58eefc3): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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: 630.278s -> 629.602s (-0.11%) |
NameBinding
values are supposed to be unique, use referential equality, and be created once for every name declaration.Before this PR many
NameBinding
s were created on name use, rather than on name declaration, because it's sufficiently cheap, and comparisons are not actually used in practice for some binding kinds.This PR makes
NameBinding
s consistently unique and created on name declaration.There are two special cases
NameBinding
requires loading the corresponding crate, which is expensive, so such bindings are created lazily on first use, but they still keep the uniqueness by being reused on further uses.