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

Move iter_results to dyn FnMut rather than a generic #84719

Merged
merged 1 commit into from
May 1, 2021

Conversation

Mark-Simulacrum
Copy link
Member

This means that we're no longer generating the iteration/locking code for each invocation site of iter_results, rather just once per query (roughly), which seems much better: this is a 15% win in instruction counts when compiling the rustc_query_impl crate. The code where this is used also is pretty cold, I suspect; the old solution didn't fully monomorphize either.

This means that we're no longer generating the iteration/locking code for each
invocation site of iter_results, rather just once per query.

This is a 15% win in instruction counts when compiling the rustc_query_impl crate.
@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 29, 2021
@Mark-Simulacrum
Copy link
Member Author

@bors try @rust-timer queue to validate my local perf results, and confirm this isn't a runtime regression

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 29, 2021
@bors
Copy link
Contributor

bors commented Apr 29, 2021

⌛ Trying commit a1d7367 with merge 002ba80ff7533e2b30773f2e042f18ab661cef2f...

@bors
Copy link
Contributor

bors commented Apr 29, 2021

☀️ Try build successful - checks-actions
Build commit: 002ba80ff7533e2b30773f2e042f18ab661cef2f (002ba80ff7533e2b30773f2e042f18ab661cef2f)

@rust-timer
Copy link
Collaborator

Queued 002ba80ff7533e2b30773f2e042f18ab661cef2f with parent 18587b1, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (002ba80ff7533e2b30773f2e042f18ab661cef2f): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 30, 2021
@Mark-Simulacrum
Copy link
Member Author

Looks like an excellent result. Much less expected in practice on parallel (rather than -j1) execution, but should still help with end-to-end times by freeing up some cores sooner.

image

@camelid
Copy link
Member

camelid commented Apr 30, 2021

There do seem to be runtime regressions for some of the benchmarks in the perf run though?

@Mark-Simulacrum
Copy link
Member Author

I'm not sure specifically what you refer to, but I'm not seeing anything that would indicate a large win like this being not warranted. There are some tiny instruction count regressions on very small benchmarks and some larger (but still in absolute terms small) regressions in wall time on one or two benchmarks; I think the win to rustc bootstrap more than exceeds those minor losses myself.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

LGTM, r=me if the perf results are acceptable (they seem good to me).

@Mark-Simulacrum
Copy link
Member Author

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented Apr 30, 2021

📌 Commit a1d7367 has been approved by davidtwco

@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 Apr 30, 2021
@bors
Copy link
Contributor

bors commented Apr 30, 2021

⌛ Testing commit a1d7367 with merge 8a9fa36...

@bors
Copy link
Contributor

bors commented May 1, 2021

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 8a9fa36 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 1, 2021
@bors bors merged commit 8a9fa36 into rust-lang:master May 1, 2021
@rustbot rustbot added this to the 1.53.0 milestone May 1, 2021
@Mark-Simulacrum Mark-Simulacrum deleted the reduce-query-impl branch May 1, 2021 01:13
Comment on lines +1188 to +1210
let mut res = Ok(());
cache.iter_results(&mut |key, value, dep_node| {
if res.is_err() {
return;
}
if Q::cache_on_disk(tcx, &key, Some(value)) {
let dep_node = SerializedDepNodeIndex::new(dep_node.index());

// Record position of the cache entry.
query_result_index.push((dep_node, AbsoluteBytePos::new(encoder.encoder.position())));

// Encode the type check tables with the `SerializedDepNodeIndex`
// as tag.
match encoder.encode_tagged(dep_node, value) {
Ok(()) => {}
Err(e) => {
res = Err(e);
}
}
}
Ok(())
})
});

res
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use a short circuit version for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what exactly you mean, but we don't really care about performance on the error path - the goal here is to minimize monomoprhizations and logic in general.

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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants