-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Long Compile Time (with Optimization) with Large Arrays (2-3 hours) #49330
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
Comments
Seems llvm is bottlenecking here
(can repro with |
Ok, it only needed 3.5 hours to compiler on a single core! timing information
|
If you come across this issue and just wonder how to work around it, one can use slices instead of arrays for this code. The diff for the reproducing code is like this, and then it compiles reasonably quickly (20 seconds) in release mode: diff --git src/main.rs src/main.rs
index 6a6d2a3..69be593 100644
--- src/main.rs
+++ src/main.rs
@@ -8,7 +8,7 @@ fn main() {
}
fn gen_adj(alpha:&String) -> String {
- let list_of_adj = [
+ let list_of_adj: &[&str] = &[
"a-ok",
"a-okay",
"a-one",
@@ -21268,7 +21268,7 @@ fn gen_adj(alpha:&String) -> String {
}
fn gen_noun(alpha:&String) -> String {
- let list_of_noun= [
+ let list_of_noun: &[&str] = &[
"a'man",
"a-bomb",
"a-horizon", The original code was using very large arrays, while using a static literal slice works just as well for the use case. |
The array was not const promoted I presume, while the slice is. Thus LLVM is trying to cope with a gigantic stack allocation. |
An update two and a half years later. This includes building dependencies: ❯ rustc +nightly --version -v
rustc 1.48.0-nightly (e2be5f568 2020-09-09)
binary: rustc
commit-hash: e2be5f568d1f60365b825530f5b5cb722460591b
commit-date: 2020-09-09
host: x86_64-pc-windows-msvc
release: 1.48.0-nightly
LLVM version: 11.0
❯ cargo +nightly build
<snip>
Finished dev [unoptimized + debuginfo] target(s) in 8m 42s
❯ cargo +nightly build --release
<snip> ... so actually I think that this got worse. I left it running for the past 8 hours, overnight, and it shows no signs of stopping. THis is on my pretty beefy desktop too. |
Summary
I have gotten very long compile time (2 hrs plus) when I tried to compile a code that has a large array inbuilt in the code when I turn optimization on. When the code is compiled without optimization, it has a acceptable compile time (10+ seconds).
The array contains 130,000 + strs.
Details
I tried this code:
I expected to see this happen: With the non-optimized code running in 11 seconds, the optimized one shouldn't take more than a few minutes.
Instead, this happened: When i waited for it to compile, it took 10039.81 secs (2 hrs 47 mins).
I replicated the problem again on a different Cargo project path and different machines and faced the same issue (didn't fully compile them as it would take very long. I waited for 5 minutes for each machine).
Environment
Machines tested:
Cargo project files attached.
nolib.zip
Meta
rustc --version --verbose
:rustc 1.22.1
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.22.1
LLVM version: 4.0
rustc 1.24.1
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.24.1
LLVM version: 4.0
rustc 1.24.1 (d3ae9a9 2018-02-27)
binary: rustc
commit-hash: d3ae9a9
commit-date: 2018-02-27
host: x86_64-pc-windows-msvc
release: 1.24.1
LLVM version: 4.0
The text was updated successfully, but these errors were encountered: