-
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
Nested async closures result in exponential compilation time increase #83031
Comments
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. |
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 I made a few Folded here is an example summary:
|
Bisected (almost certainly introduced with the original
|
Assigning |
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 #72408 with nested closures. Or this issue #75992 with levels of async, but those look to be resolved.
The text was updated successfully, but these errors were encountered: