Skip to content

Suboptimal debug codegen in rand #43299

Closed
@alexcrichton

Description

@alexcrichton

I found in one of my crates that when compiling in debug mode (cargo build) the largest function in the whole executable looked like it was this one. That looked pretty innocuous so I dug a little deeper. It turns out that function creates 1000 alloc instructions using this program as find.rs compiling this source:

$ rustc +nightly -V
rustc 1.20.0-nightly (b2c070787 2017-07-13)
$ rustc +nightly foo.rs --emit llvm-ir --crate-type lib -Z time-passes && ./find < ./foo.ll
1137 allocas

Trying to winnow it down further this source contains 337 allocas:

$ rustc +nightly foo.rs --emit llvm-ir --crate-type lib -Z time-passes && ./find < ./foo.ll
337 allocas

For comparison, the equivalent C++ program (I think? my C++ isn't very good) has only 86 allocas:

$ clang++ -emit-llvm -S foo.cpp -std=c++11 && ./find < ./foo.ll
86 allocas

Interestingly enough the C++ program compiles in ~0.035s whereas the Rust program compiles in ~0.2s, over 4x slower. The major passes in Rust 0.07s in translation, 0.03s in expansion, and 0.01s in item-bodies checking and LLVM passes. As to where the other 0.08s went in -Z time-passes I'm not sure!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-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