{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/26345607","id":26345607,"diff_hunk":"@@ -0,0 +1,185 @@\n+- Start Date: 2015-03-10\n+- RFC PR: (leave this empty)\n+- Rust Issue: (leave this empty)\n+\n+# Summary\n+\n+Make rustc and cargo produce optimized binaries by default.\n+\n+# Motivation\n+\n+\n+Optimizing by default is a safety (in the general sense) & usability feature\n+that everyone benefits from, but it's extra important for newcomers. Even\n+experienced developers coming from dynamic languages like JavaScript, Python,\n+Ruby or even static, enterprise languages like Java and C# are probably\n+completely unaware of the concept of \"debug\" and \"optimized\" builds. Note that\n+the above 5 languages represent the vast majority of the \"first language\" for\n+people learning to code today.\n+\n+`rustc` needs to be designed so that its users **[fall into the pit of\n+success](http://english.stackexchange.com/questions/77535/what-does-falling-into-the-pit-of-success-mean/77541)**.\n+Today this is sadly not the case; a newbie running `rustc foo.rs` will get a\n+slow build by default, and might easily conclude that the equivalent code they\n+wrote in Java is faster and that Rust can then be discounted. This isn't a\n+theoretical concern; situations similar to this come up on the `#rust` IRC\n+channel and on the `/r/rust` subreddit all the time.\n+\n+- [This user ran `cargo build`][ex1] and expected a fast binary, which is\n+  entirely sensible and yet _we failed them._\n+- [Here's another case.][ex2]\n+- [Yet another example.][ex3]\n+- [Experienced Rust user forgetting optimizations][ex6]. It's not just newbies\n+  who are getting bitten by this.\n+- [A user on IRC forgetting about optimizations][ex7] and thus confused about\n+  large binary size.\n+- [Seriously, we can do this all day.][ex4]\n+\n+Anyone with more that passing experience with Rust will know how to get a debug\n+build if they need one, but the default should certainly be an optimized build.\n+\n+The only reason why the unoptimized build is the default is convention started\n+many decades ago by ancient compilers that _didn't_ have an optimized build at\n+all, so when one was added later on, it was added behind a flag one had to pass\n+so as not to break the way people were using the compilers already. I don't\n+think anyone can make a reasonable case for \"unoptimized by default\" in a vacuum\n+where no previous precedent is set by other compilers.\n+\n+`rustc` should break with convention here because in this case, the conventional\n+approach _is hurtful to users._ Today's default is \"fail-deadly\" instead of being\n+\"fail-safe;\" you forget to pass a flag you might not even be aware of and you\n+get a build that's very slow and almost certainly not what you wanted.\n+\n+This problem is present with people who use C or C++ as well; StackOverflow\n+is full to the brim with examples. Here's an example from the Rust subbreddit of\n+[a user accidentally compiling C (and Haskell) code without optimizations][ex5]\n+and then comparing with Rust.\n+\n+**Debug-by-default is a poor design.** It's a footgun of massive proportions.\n+Rust is already breaking with programming convention in a myriad ways to\n+eliminate footguns (which is excellent); it should break with convention here as\n+well.\n+\n+**Let's not leave footguns in place because of obsolete conventions created by\n+backwards compatibility decisions made 40 years ago that aren't relevant to\n+Rust.**\n+\n+## Why should we do this before 1.0?\n+\n+Because doing it after 1.0 breaks backwards compatibility on a command-line\n+level. People will expect `rustc`/`cargo` to behave a certain way and will encode\n+those assumptions into their bash command history/build files/scripts/whatever.\n+\n+# Detailed design\n+\n+Change `rustc` and `cargo` to produce optimized binaries by default.\n+\n+`cargo` currently has a `--release` flag; it should also get a `--debug` flag to\n+trigger a debug build. By default, running `cargo build` is the same as running\n+`cargo build --release`.\n+\n+Similarly, `rustc` should by default run with the same flags that it would\n+receive from `cargo` if it were passed `--release`. It might make sense to also\n+add support for `--release` & `--debug` flags to `rustc`, so that with\n+`--debug` it becomes easy to instruct the compiler to not include optimizations\n+and to include debug info.\n+\n+Debate is welcome on the specifics as long as \"unadorned\" `rustc` and `cargo\n+build` calls produce optimized binaries.\n+\n+# Drawbacks\n+\n+## Slower builds by default\n+\n+Builds will only be slower _by default_; in other words, anyone calling `rustc\n+foo.rs` today can trivially call `rustc -C optlevel=0 foo.rs` or `rustc --debug\n+foo.rs` if the extra `rustc` flags are implemented.\n+\n+Note the failure state of debug-by-default: if you wanted an optimized build\n+instead, your production binary is now incredibly slow. As someone who has\n+actually pushed unoptimized binaries to production by accident, I can\n+confidently say _this costs a lot of money._\n+\n+For opt-by-default, if you actually wanted a debug build the failure state is\n+\"you waited longer for your build to finish than you should have,\" which while\n+annoying, has _far_ less potential for damage.\n+\n+## Breaks convention with compilers for other languages\n+\n+While this is a real concern, it's the result of those compilers continuing to\n+carry a legacy burden. C compilers need to be backwards compatible with the\n+state-of-the-art from many decades ago, and C++ compilers need to be compatible\n+with C compilers. In other words, they don't have a choice.\n+\n+Rust has been breaking plenty of language conventions for the sake of both\n+memory-safety and safety in general; it should continue on this commendable path\n+without being hamstrung by decisions made in 1972.\n+\n+# Alternatives\n+\n+## Only have `cargo` echo a message stating `debug` or `release` build mode","path":"text/0000-optimize-by-default.md","position":120,"original_position":120,"commit_id":"b71a1b614893135cc6ebc83861041f7751be9266","original_commit_id":"b71a1b614893135cc6ebc83861041f7751be9266","user":{"login":"reem","id":4745181,"avatar_url":"https://avatars.githubusercontent.com/u/4745181?v=3","gravatar_id":"","url":"https://api.github.com/users/reem","html_url":"https://github.com/reem","followers_url":"https://api.github.com/users/reem/followers","following_url":"https://api.github.com/users/reem/following{/other_user}","gists_url":"https://api.github.com/users/reem/gists{/gist_id}","starred_url":"https://api.github.com/users/reem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reem/subscriptions","organizations_url":"https://api.github.com/users/reem/orgs","repos_url":"https://api.github.com/users/reem/repos","events_url":"https://api.github.com/users/reem/events{/privacy}","received_events_url":"https://api.github.com/users/reem/received_events","type":"User","site_admin":false},"body":"In practice people have come to Rust from a large variety of languages, so we can't assume that they have C/C++ habits already.","created_at":"2015-03-12T21:20:33Z","updated_at":"2015-03-12T21:20:33Z","html_url":"https://github.com/rust-lang/rfcs/pull/967#discussion_r26345607","pull_request_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/967","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/26345607"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/967#discussion_r26345607"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/967"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/967","id":30912623,"html_url":"https://github.com/rust-lang/rfcs/pull/967","diff_url":"https://github.com/rust-lang/rfcs/pull/967.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/967.patch","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/967","number":967,"state":"open","locked":false,"title":"Make rustc and cargo produce optimized binaries by default","user":{"login":"Valloric","id":919444,"avatar_url":"https://avatars.githubusercontent.com/u/919444?v=3","gravatar_id":"","url":"https://api.github.com/users/Valloric","html_url":"https://github.com/Valloric","followers_url":"https://api.github.com/users/Valloric/followers","following_url":"https://api.github.com/users/Valloric/following{/other_user}","gists_url":"https://api.github.com/users/Valloric/gists{/gist_id}","starred_url":"https://api.github.com/users/Valloric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Valloric/subscriptions","organizations_url":"https://api.github.com/users/Valloric/orgs","repos_url":"https://api.github.com/users/Valloric/repos","events_url":"https://api.github.com/users/Valloric/events{/privacy}","received_events_url":"https://api.github.com/users/Valloric/received_events","type":"User","site_admin":false},"body":"Make rustc and cargo produce optimized binaries by default.\r\n\r\n[Rendered.](https://github.com/Valloric/rfcs/blob/opt-by-def/text/0000-optimize-by-default.md)","created_at":"2015-03-11T03:15:37Z","updated_at":"2015-03-12T21:20:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9c605046af89d159f6717e25cc5c3bcc6ba7eda2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/967/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/967/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/967/comments","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/b71a1b614893135cc6ebc83861041f7751be9266","head":{"label":"Valloric:opt-by-def","ref":"opt-by-def","sha":"b71a1b614893135cc6ebc83861041f7751be9266","user":{"login":"Valloric","id":919444,"avatar_url":"https://avatars.githubusercontent.com/u/919444?v=3","gravatar_id":"","url":"https://api.github.com/users/Valloric","html_url":"https://github.com/Valloric","followers_url":"https://api.github.com/users/Valloric/followers","following_url":"https://api.github.com/users/Valloric/following{/other_user}","gists_url":"https://api.github.com/users/Valloric/gists{/gist_id}","starred_url":"https://api.github.com/users/Valloric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Valloric/subscriptions","organizations_url":"https://api.github.com/users/Valloric/orgs","repos_url":"https://api.github.com/users/Valloric/repos","events_url":"https://api.github.com/users/Valloric/events{/privacy}","received_events_url":"https://api.github.com/users/Valloric/received_events","type":"User","site_admin":false},"repo":{"id":20387233,"name":"rfcs","full_name":"Valloric/rfcs","owner":{"login":"Valloric","id":919444,"avatar_url":"https://avatars.githubusercontent.com/u/919444?v=3","gravatar_id":"","url":"https://api.github.com/users/Valloric","html_url":"https://github.com/Valloric","followers_url":"https://api.github.com/users/Valloric/followers","following_url":"https://api.github.com/users/Valloric/following{/other_user}","gists_url":"https://api.github.com/users/Valloric/gists{/gist_id}","starred_url":"https://api.github.com/users/Valloric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Valloric/subscriptions","organizations_url":"https://api.github.com/users/Valloric/orgs","repos_url":"https://api.github.com/users/Valloric/repos","events_url":"https://api.github.com/users/Valloric/events{/privacy}","received_events_url":"https://api.github.com/users/Valloric/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Valloric/rfcs","description":"RFCs for changes to Rust","fork":true,"url":"https://api.github.com/repos/Valloric/rfcs","forks_url":"https://api.github.com/repos/Valloric/rfcs/forks","keys_url":"https://api.github.com/repos/Valloric/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Valloric/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Valloric/rfcs/teams","hooks_url":"https://api.github.com/repos/Valloric/rfcs/hooks","issue_events_url":"https://api.github.com/repos/Valloric/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/Valloric/rfcs/events","assignees_url":"https://api.github.com/repos/Valloric/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/Valloric/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/Valloric/rfcs/tags","blobs_url":"https://api.github.com/repos/Valloric/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Valloric/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Valloric/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/Valloric/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Valloric/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/Valloric/rfcs/languages","stargazers_url":"https://api.github.com/repos/Valloric/rfcs/stargazers","contributors_url":"https://api.github.com/repos/Valloric/rfcs/contributors","subscribers_url":"https://api.github.com/repos/Valloric/rfcs/subscribers","subscription_url":"https://api.github.com/repos/Valloric/rfcs/subscription","commits_url":"https://api.github.com/repos/Valloric/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/Valloric/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/Valloric/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/Valloric/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/Valloric/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/Valloric/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Valloric/rfcs/merges","archive_url":"https://api.github.com/repos/Valloric/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Valloric/rfcs/downloads","issues_url":"https://api.github.com/repos/Valloric/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/Valloric/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/Valloric/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/Valloric/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Valloric/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/Valloric/rfcs/releases{/id}","created_at":"2014-06-01T21:48:30Z","updated_at":"2015-03-01T17:58:30Z","pushed_at":"2015-03-11T05:34:24Z","git_url":"git://github.com/Valloric/rfcs.git","ssh_url":"git@github.com:Valloric/rfcs.git","clone_url":"https://github.com/Valloric/rfcs.git","svn_url":"https://github.com/Valloric/rfcs","homepage":"","size":1559,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"dab3e4b3f087e7bb49c3314be65adee20c094889","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":17527989,"name":"rfcs","full_name":"rust-lang/rfcs","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rfcs","description":"RFCs for changes to Rust","fork":false,"url":"https://api.github.com/repos/rust-lang/rfcs","forks_url":"https://api.github.com/repos/rust-lang/rfcs/forks","keys_url":"https://api.github.com/repos/rust-lang/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rfcs/teams","hooks_url":"https://api.github.com/repos/rust-lang/rfcs/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rfcs/events","assignees_url":"https://api.github.com/repos/rust-lang/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rfcs/tags","blobs_url":"https://api.github.com/repos/rust-lang/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rfcs/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rfcs/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rfcs/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rfcs/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rfcs/subscription","commits_url":"https://api.github.com/repos/rust-lang/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rfcs/merges","archive_url":"https://api.github.com/repos/rust-lang/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rfcs/downloads","issues_url":"https://api.github.com/repos/rust-lang/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rfcs/releases{/id}","created_at":"2014-03-07T21:29:00Z","updated_at":"2015-03-11T20:39:41Z","pushed_at":"2015-03-06T16:19:34Z","git_url":"git://github.com/rust-lang/rfcs.git","ssh_url":"git@github.com:rust-lang/rfcs.git","clone_url":"https://github.com/rust-lang/rfcs.git","svn_url":"https://github.com/rust-lang/rfcs","homepage":"","size":10887,"stargazers_count":278,"watchers_count":278,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":173,"mirror_url":null,"open_issues_count":467,"forks":173,"open_issues":467,"watchers":278,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/967"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/967"},"issue":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/967"},"comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/967/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/967/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/967/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rfcs/statuses/b71a1b614893135cc6ebc83861041f7751be9266"}}}}