-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Skip query in get_parent_item when possible. #130623
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Skip query in get_parent_item when possible. `self.parent_owner_iter(hir_id).next()` does a query to retrieve the Node which is ignored here, which seems wasteful.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (a7239e7): comparison URL. Overall result: ❌✅ regressions and improvements - 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)Results (primary 1.3%, secondary 1.6%)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.
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: 768.108s -> 768.119s (0.00%) |
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 don't know which of these two PRs you'd rather land, but also I don't expect this function to be very hot or called much (or at all?) outside of diagnostics. I somewhat prefer #130618 due to the simplicity, though.
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID { | ||
hir_id.owner | ||
} else if let Some(local_def_index) = self.def_key(hir_id.owner.def_id).parent { | ||
self.tcx.local_def_id_to_hir_id(LocalDefId { local_def_index }).owner |
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.
self.tcx.local_def_id_to_hir_id(LocalDefId { local_def_index }).owner | |
self.tcx.local_def_id_to_hir_id(LocalDefId { local_def_index }).expect_owner() |
@@ -598,8 +598,10 @@ impl<'hir> Map<'hir> { | |||
/// in the HIR which is recorded by the map and is an item, either an item | |||
/// in a module, trait, or impl. | |||
pub fn get_parent_item(self, hir_id: HirId) -> OwnerId { | |||
if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() { | |||
def_id | |||
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID { |
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.
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID { | |
if hir_id.local_id.index() != 0 || hir_id.owner == CRATE_OWNER_ID { | |
// If this is a child of a HIR owner, return the owner. | |
// If we're at the top of the HIR tree, then the crate is its own parent. |
I was just testing if it made a practical difference, not sure if it's worth landing either of them given there's no measurable impact. |
self.parent_owner_iter(hir_id).next()
does a query to retrieve the Node which is ignored here, which seems wasteful.