Skip to content

Long compile/optimization times with chained Option iterators #49402

Closed
@smangelsdorf

Description

@smangelsdorf

When using chained option iterators to build a collection, I found that compile times in release mode were longer than I expected. Originally this was reported on the Gotham gitter channel, and I wrote the following PR which has drastically improved the compile times on my machine:

gotham-rs/gotham#194

To reproduce the issue in a more useful way, I've written the following which doesn't finish compiling in the rust playground:

https://play.rust-lang.org/?gist=de324d04c49e0702326210342a6e7d30&version=stable

This same code compiles on my machine in approximately 2 seconds (or 3.5 seconds with rustc -O), vs ~150ms for a simple "Hello, world!" style application.

Rightly or wrongly, I didn't expect the impact on compile times to be this drastic, though I feel that I've just hit an edge case and the easiest answer is to write better Rust code.

Compile time on Gotham's 0.2-maint branch, which didn't yet have the above PR merged:

(rustc CPU usage was sitting at 100% of a single core for the duration)

$ cargo build --release
   Compiling gotham v0.2.1-dev
    Finished release [optimized] target(s) in 1047.79 secs

Output with -Z time-passes

Compile time on the branch used to submit the above PR:

$ cargo build --release
   Compiling gotham v0.2.1-dev
    Finished release [optimized] target(s) in 5.38 secs

Output with -Z time-passes

On scanning the issue tracker, I found #22204 which may be the same problem, but I'm not entirely sure.

Meta

I tried this on my stable and nightly compilers, which both exhibited the same behaviour. The output above is from my nightly compiler.

$ rustc --version --verbose
rustc 1.26.0-nightly (482a913fb 2018-03-25)
binary: rustc
commit-hash: 482a913fb337855072a53c0d602cd19947f45285
commit-date: 2018-03-25
host: x86_64-apple-darwin
release: 1.26.0-nightly
LLVM version: 6.0
$ rustc +stable --version --verbose
rustc 1.24.0 (4d90ac38c 2018-02-12)
binary: rustc
commit-hash: 4d90ac38c0b61bb69470b61ea2cccea0df48d9e5
commit-date: 2018-02-12
host: x86_64-apple-darwin
release: 1.24.0
LLVM version: 4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions