Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Sep 20, 2024

self.parent_owner_iter(hir_id).next() does a query to retrieve the Node which is ignored here, which seems wasteful.

@m-ou-se m-ou-se added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Sep 20, 2024
@m-ou-se m-ou-se self-assigned this Sep 20, 2024
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 20, 2024
@m-ou-se
Copy link
Member Author

m-ou-se commented Sep 20, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 20, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 20, 2024
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.
@bors
Copy link
Contributor

bors commented Sep 20, 2024

⌛ Trying commit edca9c2 with merge a7239e7...

@bors
Copy link
Contributor

bors commented Sep 20, 2024

☀️ Try build successful - checks-actions
Build commit: a7239e7 (a7239e7ba849aa3166777f656b9732c9208f8ea5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a7239e7): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.3%, -0.1%] 3
All ❌✅ (primary) - - 0

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.

mean range count
Regressions ❌
(primary)
5.5% [5.5%, 5.5%] 1
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.3% [-2.9%, 5.5%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 768.108s -> 768.119s (0.00%)
Artifact size: 341.28 MiB -> 341.21 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 20, 2024
Copy link
Member

@compiler-errors compiler-errors left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

@m-ou-se
Copy link
Member Author

m-ou-se commented Sep 23, 2024

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.

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.

@m-ou-se m-ou-se closed this Sep 23, 2024
@m-ou-se m-ou-se deleted the skip-query2 branch September 23, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants