Open blazzy opened 3 years ago
cargo --release
builds everything a lot faster(edit: <- this was wrong), but it still has the exponential time increase issue.
I also tried making a nested async version without the generic functions.
pub async fn my_middleware<N, Fut>(route: N)
where
N: FnOnce() -> Fut,
Fut: Future<Output = ()>,
{
(| | async { (| | async { (| | async { (| | async { (| | async { (| | async { (| | async { (| | async { (| | async { (| | async { (| | async { (| | async move { route () . await }) () . await }) () . await }) () . await }) () . await }) () . await }) () . await }) () . await }) () . await }) () . await }) () . await }) () . await }) () . await
}
And I tried making a nested generic function version without the async:
pub fn my_middleware<N>(route: N)
where
N: FnOnce() -> (),
{
log(|| {
log(|| {
log(|| {
log(|| {
...
log(route);
});
});
});
})
}
Both of these versions compiled very quickly and don't exhibit the exponential problem.
Release mode being faster suggests that the slowdown is happening after MIR optimization somewhere.
Possible duplicate of #75992 or #54540.
I closed those other issues, so we can keep this issue open. (Those issues might still be a good source of test cases / benchmarks.)
Sorry, the --release
builds don't actually seem to be faster. I was getting less rigorous in keeping track of what I was measuring as I multi-tasked and waited for minutes long builds to complete.
I made a few cargo rustc -- -Zself-profile
runs. It's consistently dominated by mir_borrowck
and check_mod_privacy
.
Bisected (almost certainly introduced with the original await
PR), when this first compiled.
********************************************************************************
Regression in nightly-2019-05-09
********************************************************************************
fetching https://static.rust-lang.org/dist/2019-05-08/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2019-05-08: 40 B / 40 B [===============] 100.00 % 652.99 KB/s converted 2019-05-08 to cfdc84a009020c59e53e4039beae22eb59e41685
fetching https://static.rust-lang.org/dist/2019-05-09/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2019-05-09: 40 B / 40 B [===============] 100.00 % 683.02 KB/s converted 2019-05-09 to 3f5152e200c0c02dfe0f79367948c98053d35855
looking for regression commit between 2019-05-08 and 2019-05-09
opening existing repository at "rust.git"
refreshing repository
fetching (via local git) commits from cfdc84a009020c59e53e4039beae22eb59e41685 to 3f5152e200c0c02dfe0f79367948c98053d35855
opening existing repository at "rust.git"
refreshing repository
looking up first commit
looking up second commit
checking that commits are by bors and thus have ci artifacts...
finding bors merge commits
found 6 bors merge commits in the specified range
commit[0] 2019-05-07UTC: Auto merge of #60612 - Centril:rollup-61drhqt, r=Centril
commit[1] 2019-05-07UTC: Auto merge of #60586 - cramertj:await, r=oli-obk
commit[2] 2019-05-08UTC: Auto merge of #60378 - froydnj:apple-target-modifications, r=michaelwoerister
commit[3] 2019-05-08UTC: Auto merge of #60246 - Zoxc:hir-map-vec, r=eddyb
commit[4] 2019-05-08UTC: Auto merge of #60626 - matthiaskrgr:submodule_upd, r=oli-obk
commit[5] 2019-05-08UTC: Auto merge of #60402 - michaelwoerister:update-profiler-rt-build, r=alexcrichton
ERROR: no commits between cfdc84a009020c59e53e4039beae22eb59e41685 and 3f5152e200c0c02dfe0f79367948c98053d35855 within last 167 days
Assigning P-medium
as discussed as part of the Prioritization Working Group procedure and removing I-prioritize
.
I've noticed exponential increases in compilation times as I nest async closures within each other.
I tried this code:
That
compose_middleware!
macro invocation generates a function that looks something like this:I expected to see this happen: I expected this code to build within seconds
Instead, this happened: At around 3 levels it takes less than a second to build. At around 9 levels it takes around a minute to build. At around 14 levels it takes around 10 minutes to build.
Meta
I've experienced this issue on nightly, stable, and beta. And I've sampled random nightly versions going back as far as 1.39 and still witnessed the problem. There was a good bit of variability in build times, but it generally seemed to increase exponentially.
I threw this little repo up to test the issue: https://github.com/blazzy/slow-rust-async/blob/master/src/lib.rs
I thought it might be related to this issue https://github.com/rust-lang/rust/issues/72408 with nested closures. Or this issue https://github.com/rust-lang/rust/issues/75992 with levels of async, but those look to be resolved.