Skip to content

Compile-time regression between 1.56.1 and 1.57.0 for deeply nested decorator types #91598

Closed
@nightkr

Description

@nightkr

1.57.0 seems to have brought a pretty deep regression in compile times for deeply nested "decorator" types, such as futures' Stream combinators.

This is a minimized version of kube-rs/kube#746.

Code

I tried this code:

use futures::{stream, StreamExt, TryStreamExt};

fn main() {
    stream::empty::<Result<(), ()>>()
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        // .boxed()
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        // .boxed()
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        // .boxed()
        .inspect_ok(|_| ())
        .inspect_ok(|_| ())
        .inspect_ok(|_| ());
}

In Rust 1.56.1, this builds in ~0.7s on my machine (excluding time spent compiling futures and its dependencies).

In Rust 1.57.0 (and the latest nightly), this takes several minutes.

Curiously, boxing into a trait object (by uncommenting the .boxed() calls) seems to act as a type checking boundary, and makes rustc 1.57.0 build it in ~0.55s.

Version it worked on

It most recently worked on: Rust 1.56.1

Version with regression

rustc --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)

Backtrace

There was no crash, so there is no backtrace to report.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.P-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions