# Optimizing by default

**URL:** <https://internals.rust-lang.org/t/optimizing-by-default/1532>\
**Category:** internals\
**Created:** [February 4, 2015, 12:41am UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532 "2015-02-04T00:41:05Z")\
**Posts on this page:** 16\
**Page:** 3

<div class="post-metadata">

**Author:** ![Valloric](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/valloric/32/9611_2.png) [@Valloric](https://internals.rust-lang.org/u/Valloric)\
**Post date:** [February 26, 2015, 5:00pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/41 "2015-02-26T17:00:56Z")

</div>

[Yet another example](http://learncamlirust.blogspot.de/2015/02/day-1-porting-rollingsum.html) of a newcomer to Rust using unoptimized builds by accident and concluding that Rust is slow.

---

<div class="post-metadata">

**Author:** ![tbu](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tbu](https://internals.rust-lang.org/u/tbu)\
**Post date:** [February 26, 2015, 9:07pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/42 "2015-02-26T21:07:54Z")

</div>

From my Github comment:

> Complaining about the status quo _like this_ is not necessarily good – you can't see if the other option would raise similar problems with users about the even slower compilation speed.

What I mean is that you **obviously** don't get user stories about overlong compilation times, because currently, release is not the default.

---

<div class="post-metadata">

**Author:** ![llogiq](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/llogiq/32/13692_2.png) [@llogiq](https://internals.rust-lang.org/u/llogiq)\
**Post date:** [February 27, 2015, 1:24pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/43 "2015-02-27T13:24:08Z")

</div>

And [one more example](http://www.reddit.com/r/rust/comments/2xccw8/performance_of_reading_a_large_file/).

Yep, it really trips people.

---

<div class="post-metadata">

**Author:** ![vks](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/vks/32/3632_2.png) [@vks](https://internals.rust-lang.org/u/vks)\
**Post date:** [February 27, 2015, 3:14pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/44 "2015-02-27T15:14:35Z")

</div>

I agree that optimizing is a much more reasonable default. The increased compile time shouldn’t be an issue for new users, and experienced users can explicitly pass the debug flag. I also would prefer this option over noisy warnings.

---

<div class="post-metadata">

**Author:** ![llogiq](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/llogiq/32/13692_2.png) [@llogiq](https://internals.rust-lang.org/u/llogiq)\
**Post date:** [February 27, 2015, 3:38pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/45 "2015-02-27T15:38:42Z")

</div>

Could there be a reasonable middle ground — that is, optimize, but not to the point of losing debugging information? Yes, it might make compilation a bit slower (though not as slow as --release/-O3), but it won’t trip newbies as hard. Then --debug could still disable all optimizations, while --release enables all.

---

<div class="post-metadata">

**Author:** ![tbu](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tbu](https://internals.rust-lang.org/u/tbu)\
**Post date:** [February 27, 2015, 3:42pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/46 "2015-02-27T15:42:31Z")

</div>

But then you have a not-so-obviously incorrect solution. It works somewhat fast but not as fast as it could. The current non-solution at least makes it obvious that something is wrong, people are asking others what they are doing wrong.

---

<div class="post-metadata">

**Author:** ![llogiq](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/llogiq/32/13692_2.png) [@llogiq](https://internals.rust-lang.org/u/llogiq)\
**Post date:** [February 27, 2015, 3:48pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/47 "2015-02-27T15:48:39Z")

</div>

So you want full optimization settings on by default, so that enough people complain about the compiler being slow which compels the rust team to improve the compiler. Clever. Sneaky, yes, but clever. 😄

---

<div class="post-metadata">

**Author:** ![carllerche](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/carllerche/32/530_2.png) [@carllerche](https://internals.rust-lang.org/u/carllerche)\
**Post date:** [February 27, 2015, 8:11pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/48 "2015-02-27T20:11:38Z")

</div>

It should also be possible to add a local config (stored in ~/.cargo/config) that allows changing the default options for `cargo build`

---

<div class="post-metadata">

**Author:** ![DanielKeep](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/danielkeep/32/1332_2.png) [@DanielKeep](https://internals.rust-lang.org/u/DanielKeep)\
**Post date:** [February 27, 2015, 11:56pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/49 "2015-02-27T23:56:56Z")

</div>

I don’t see why we can’t just have both `cargo` and `rustc` _tell_ the user what they’re doing by default. If you don’t specify debug/release or an optimisation level, the compiler just says the equivalent of “oh, by the way, I’m compiling in debug mode with no optimisations.”

_Silently_ changing the default will just shift complaints to “man, Rust takes forever to compile, even when I’m not asking for optimisation!” and we’ll be back here arguing over changing the default back.

---

<div class="post-metadata">

**Author:** ![comex](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/comex/32/2587_2.png) [@comex](https://internals.rust-lang.org/u/comex)\
**Post date:** [February 28, 2015, 12:51am UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/50 "2015-02-28T00:51:52Z")

</div>

Well, it’s a pretty well-regarded (if often ignored) tradition that Unix programs should be silent on success. (This only matters for `rustc`; `cargo` is already noisy of course.)

---

<div class="post-metadata">

**Author:** ![DanielKeep](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/danielkeep/32/1332_2.png) [@DanielKeep](https://internals.rust-lang.org/u/DanielKeep)\
**Post date:** [February 28, 2015, 6:51am UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/51 "2015-02-28T06:51:21Z")

</div>

I think educating users is more important than blind adherence to tradition in the face of clear practical disadvantages.

---

<div class="post-metadata">

**Author:** ![tbu](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tbu](https://internals.rust-lang.org/u/tbu)\
**Post date:** [February 28, 2015, 12:40pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/52 "2015-02-28T12:40:15Z")

</div>

I don’t think we need to make `rustc` noisy, making `cargo`'s output more obvious in that regard should be fine.

---

<div class="post-metadata">

**Author:** ![tanadeau](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tanadeau/32/5419_2.png) [@tanadeau](https://internals.rust-lang.org/u/tanadeau)\
**Post date:** [March 6, 2015, 5:50am UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/53 "2015-03-06T05:50:47Z")

</div>

There’s currently a [Cargo PR](https://github.com/rust-lang/cargo/pull/1374) by @alexcrichton to have it output the used build profile (release or debug).

---

<div class="post-metadata">

**Author:** ![iox](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/iox/32/4407_2.png) [@iox](https://internals.rust-lang.org/u/iox)\
**Post date:** [March 10, 2015, 10:04pm UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/54 "2015-03-10T22:04:40Z")

</div>

[Here](https://www.reddit.com/r/rust/comments/2yk5z7/why_this_rust_code_slower_than_c/) is another example of someone getting confused by this.

---

<div class="post-metadata">

**Author:** ![Valloric](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/valloric/32/9611_2.png) [@Valloric](https://internals.rust-lang.org/u/Valloric)\
**Post date:** [March 11, 2015, 3:30am UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/55 "2015-03-11T03:30:08Z")

</div>

[I created an RFC](https://github.com/rust-lang/rfcs/pull/967) asking for `rustc` and `cargo` to produce optimized code by default.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:23am UTC](https://internals.rust-lang.org/t/optimizing-by-default/1532/56 "2019-03-25T08:23:50Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/optimizing-by-default/1532.md?page=2)
