-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Description
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!