-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Compiling small program with -C opt-level=2 takes hours or never finishes without -Cinline-threshold flag #86870
Comments
With opt-level 0 or 1 it compiles instant both versions. With
Is it expected for your code? |
That's right klensy. This generated code was more about stressing the compiler than actually running the resulting program. With low optimization or debug compilation the code triggers 'attempt to multiply with overflow'. The higher opt-level such as 2 turns off that check I believe. The 20 function versions - Note the 500 function (or more) versions are scaled up version intended to stress a compiler. If a larger version that still outputs a result is useful, Here's a 300 function version where the executable produced by |
You know, I though if the arithmetic should wrap around, why not use So, I, actually, try it out and replaced all the But I don't really understand, why this makes such a big difference for the compiler.
Edit: I get similar results for the 300 functions test, that is 2.0 s for wrapping-Rust compilation and 1.6 s for C++. But I could also test the resulting binaries, which give the same output of course, the Rust binary runs for 3.6 s whereas the C++ binary run for 8.7 s, on my machine. |
Nice Cryptjar! I hadn't thought about using To add to that, on my machine at least, compiling with Actually running the 300 functions test executable produced, the |
maybe compiler use bigint to compile time the result |
The code necessary to panic for each checked operation is going to be quite large, and introduce a fair number of additional basic blocks. Ideally compilation would still be linear wrt the amount of code (rather than superlinear). |
So whats going on with this issue? |
Hi!
Background
I generated a small identical program in Rust and C++. See for instance:
Benchmarking the compilation of this code (using hyperfine) I find:
Expectation vs. reality
I would expect Rust to have similar optimizing performance to clang in this case. That is, compiling in seconds without an obscure compiler flag. Instead, it effectively fails to compile by never finishing. As a Rust newb this behavior is not very friendly. Is there a reasonable limit like comes into play with the
-Cinline-threshold
flag that should be included in the optimization flags (suchopt-level=2
) by default, or a way to otherwise stop the compiler from falling down an endless or futile pit?Thank you
Thank you for you time, I hope this issue can improve Rust. There is the accompanying StackOverflow posting where I learned about the
-Cinline-threshold
flag and userbluss
recommended a bug report here.rustc
versions used; I previously replicated this on Linux and OS X as well.Here is the 20 function Rust code for reference if the gists ever stops working:
The text was updated successfully, but these errors were encountered: