Skip to content

rustc should notify users when optimizations are disabled #777

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

Closed
tanadeau opened this issue Feb 2, 2015 · 11 comments
Closed

rustc should notify users when optimizations are disabled #777

tanadeau opened this issue Feb 2, 2015 · 11 comments
Labels
T-cargo Relevant to the Cargo team, which will review and decide on the RFC. T-compiler Relevant to the compiler team, which will review and decide on the RFC. T-doc Relevant to the documentation team, which will review and decide on the RFC.

Comments

@tanadeau
Copy link

tanadeau commented Feb 2, 2015

As the Rust community gets more developers coming from JIT'ed or interpreted languages like Java, Python, Ruby, etc., we are going to see more problems where they assume rustc my_file.rs will give fast results even though optimizations are off by default. This can be seen in several threads on Stack Overflow and other forums, including Rust's own (http://users.rust-lang.org/t/reading-numbers-from-a-file/171).

I suggest that when no optimization flags are enabled, rustc should print out a message similar to the following:

rustc my_file.rs
Note: Optimizations are disabled (debug mode). Turn them on by passing the -O flag.
@sinistersnare
Copy link

This might be better suited as a Cargo feature, which has text that appears when compiling.

@tanadeau
Copy link
Author

tanadeau commented Feb 2, 2015

@sinistersnare I think it should probably be in both rustc and Cargo, now that you mentioned it. Many beginners are probably not going to use Cargo for their first little hello world-type tests apps, even though they probably should. I know I didn't, especially since the source tarballs with script installers and package managers like Homebrew don't yet include it.

@Valloric
Copy link

Valloric commented Feb 2, 2015

This would be a good idea. Newbies not compiling with optimizations and then complaining about perf issues is a perennial problem with C++ and it's becoming an issue with Rust as well. Just nip this in the bud with a note.

@sfackler
Copy link
Member

sfackler commented Feb 2, 2015

OTOH, it seems like it would be annoying for everyone who's not a newbie to be reminded that they don't have optimizations enabled every time they build.

@reem
Copy link

reem commented Feb 3, 2015

I would prefer if this was a cargo feature, that way it would only warn once rather than for every single invocation of rustc.

@Valloric
Copy link

Valloric commented Feb 3, 2015

OTOH, it seems like it would be annoying for everyone who's not a newbie to be reminded that they don't have optimizations enabled every time they build.

If the user explicitly passes -O0, then the note should not appear.

The idea is that you either know what you're doing, or rustc makes sure that you do.

@tanadeau
Copy link
Author

tanadeau commented Feb 3, 2015

@Valloric Yes. That's exactly the idea I was going for.

@Valloric
Copy link

Valloric commented Feb 3, 2015

Now that I think about it, I think this issue is going about the problem the wrong way.

IMO the real solution would be to make rustc compile with optimizations by default, and the user must pass -O0 explicitly if they want a debug build. This is the safer approach; if the user forgets a flag, the "failure mode" is they don't have a debug binary when they wanted one instead of them pushing an unoptimized build to production. The first is a nuisance, the second is a disaster (which has bit me in real life more than once).

@tanadeau
Copy link
Author

tanadeau commented Feb 3, 2015

@Valloric I did think of that, but I didn't include that in the issue since there seems to be some strong resistance to "optimize by default" at least within Cargo. See rust-lang/cargo#784 for a somewhat similar discussion there. Turning on optimization by default would definitely be my preference.

@tanadeau
Copy link
Author

tanadeau commented Feb 3, 2015

I should also note that I would be okay (although not enthusiastic) about having this just be a Cargo feature if all of the docs pointed people towards Cargo, which is definitely not the case now. The hello world in the Rust book has people use rustc (http://doc.rust-lang.org/book/hello-world.html).

@petrochenkov petrochenkov added T-compiler Relevant to the compiler team, which will review and decide on the RFC. T-doc Relevant to the documentation team, which will review and decide on the RFC. T-cargo Relevant to the Cargo team, which will review and decide on the RFC. labels Jan 28, 2018
@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Closing in favor of rust-lang/cargo#6152.

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-cargo Relevant to the Cargo team, which will review and decide on the RFC. T-compiler Relevant to the compiler team, which will review and decide on the RFC. T-doc Relevant to the documentation team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

7 participants