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

Avoid unnecessary work in finalize_resolutions_in. #98569

Merged
merged 1 commit into from
Jul 3, 2022

Conversation

nnethercote
Copy link
Contributor

If module.opt_def_id() returns None, we can skip most of the work.

r? @lqd

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 27, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 27, 2022
@nnethercote
Copy link
Contributor Author

This is a 1% win on the c2-chacha-0.3.3 crate (check full build) and has little effect on anything else.

@lqd
Copy link
Member

lqd commented Jun 28, 2022

I'm not super familiar with the resolver, and the change seems OK, but I wonder if this could impact resolutions to the modules where it's done lazily, e.g. their possible errors / ambiguities ?

I would trust tests (esp with #[macro_export]) to tell us that if that's the case, but I wonder if we do have tests exercizing this code path, do you happen to know that ?

r=me if that's the case, and if we ever need this PR to be easy to find for bisection:

@bors rollup=never

@nnethercote
Copy link
Contributor Author

nnethercote commented Jun 28, 2022

The idea here is that functionality shouldn't be changed.

The current code creates reexports. It doesn't modify anything else while doing so. Then, if if let Some(def_id) = module.opt_def_id() succeeds, it does something with reexports. Otherwise, it does nothing.

I just rearranged things so that reexports isn't built in the "it does nothing" case.

That's why I asked a non-resolve-expert for the review, because it's just a minor code rearrangement :)

@lqd
Copy link
Member

lqd commented Jun 28, 2022

To clarify, I meant that for_each_child seemed to be able to mutate resolutions, and was wondering whether we knew of modules "populated on access" and if so, whether finalize_resolutions_id could be involved in populating them ?

fn for_each_child<R, F>(&'a self, resolver: &mut R, mut f: F)
where
R: AsMut<Resolver<'a>>,
F: FnMut(&mut R, Ident, Namespace, &'a NameBinding<'a>),
{
for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() {
if let Some(binding) = name_resolution.borrow().binding {
f(resolver, key.ident, key.ns, binding);
}
}
}
and in turn
fn resolutions(&mut self, module: Module<'a>) -> &'a Resolutions<'a> {
if module.populate_on_access.get() {
module.populate_on_access.set(false);
self.build_reduced_graph_external(module);
}
&module.lazy_resolutions
}

@nnethercote
Copy link
Contributor Author

r? @cjgillot

@rust-highfive rust-highfive assigned cjgillot and unassigned lqd Jun 28, 2022
If `module.opt_def_id()` returns `None`, we can skip most of the work.
@nnethercote nnethercote force-pushed the finalize_resolutions_id branch from 4fe2967 to 0e475b5 Compare June 28, 2022 23:21
@nnethercote nnethercote changed the title Avoid unnecessary work in finalize_resolutions_id. Avoid unnecessary work in finalize_resolutions_in. Jun 28, 2022
@petrochenkov
Copy link
Contributor

whether finalize_resolutions_id could be involved in populating them

Nah, only modules from other crates are lazily populated, and the less of them is populated the better.
Modules without a def-id cannot be extern though, so in this PR is shouldn't make any difference.

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 30, 2022

📌 Commit 0e475b5 has been approved by cjgillot

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 30, 2022
@bors
Copy link
Contributor

bors commented Jul 2, 2022

⌛ Testing commit 0e475b5 with merge 5f98537...

@bors
Copy link
Contributor

bors commented Jul 3, 2022

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 5f98537 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 3, 2022
@bors bors merged commit 5f98537 into rust-lang:master Jul 3, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 3, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5f98537): comparison url.

Instruction count

  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
0.3% 0.5% 7
Regressions 😿
(secondary)
0.5% 0.7% 7
Improvements 🎉
(primary)
-1.0% -1.0% 2
Improvements 🎉
(secondary)
-2.1% -2.4% 6
All 😿🎉 (primary) 0.0% -1.0% 9

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: 😿 relevant regression found
mean1 max count2
Regressions 😿
(primary)
2.4% 2.4% 1
Regressions 😿
(secondary)
3.3% 3.3% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) 2.4% 2.4% 1

Cycles

Results
  • Primary benchmarks: mixed results
  • Secondary benchmarks: no relevant changes found
mean1 max count2
Regressions 😿
(primary)
2.2% 2.2% 1
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-3.4% -4.7% 2
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) -1.5% -4.7% 3

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added the perf-regression Performance regression. label Jul 3, 2022
@nnethercote nnethercote deleted the finalize_resolutions_id branch July 4, 2022 07:17
@nnethercote
Copy link
Contributor Author

Slightly unexpected perf results, but the wins and losses more or less balance out so I don't think we need to worry about it.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants