Skip to content
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

Avoid codegen for Result::into_ok in lang_start #88988

Merged
merged 1 commit into from
Sep 18, 2021

Conversation

Mark-Simulacrum
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum commented Sep 15, 2021

This extra codegen seems to be the cause for the regressions in max-rss on #86034. While LLVM will certainly optimize the dead code away, avoiding it's generation in the first place seems good, particularly when it is so simple.

#86034 produced this diff for a simple fn main() {}. With this PR, that diff becomes limited to just a few extra IR instructions -- no extra functions.

Note that these are pre-optimization; LLVM surely will eliminate this during optimization. However, that optimization can end up generating more work and bump memory usage, and this eliminates that.

@rust-highfive
Copy link
Collaborator

r? @yaahc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2021
@Mark-Simulacrum
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 15, 2021
@bors
Copy link
Contributor

bors commented Sep 15, 2021

⌛ Trying commit 76e71b012bd77dc310ce036e14fb56b2d9e0a43d with merge 526cb50d2abbf6ee2ee3c62cabe2ce1735313f63...

@bors
Copy link
Contributor

bors commented Sep 15, 2021

☀️ Try build successful - checks-actions
Build commit: 526cb50d2abbf6ee2ee3c62cabe2ce1735313f63 (526cb50d2abbf6ee2ee3c62cabe2ce1735313f63)

@rust-timer
Copy link
Collaborator

Queued 526cb50d2abbf6ee2ee3c62cabe2ce1735313f63 with parent 2c7bc5e, future comparison URL.

Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we may want to open-code map_err in the function above as well which would likely help too.

library/std/src/rt.rs Outdated Show resolved Hide resolved
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (526cb50d2abbf6ee2ee3c62cabe2ce1735313f63): comparison url.

Summary: This change led to large relevant improvements 🎉 in compiler performance.

  • Large improvement in instruction counts (up to -4.4% on incr-full builds of helloworld)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 16, 2021
Otherwise, we end up pulling in an extra module as part of codegen, and that
costs us a sizeable amount of work (both in LLVM and outside).
@Mark-Simulacrum
Copy link
Member Author

I feel like we may want to open-code map_err in the function above as well which would likely help too.

lang_start_internal is already codegen'd as part of std, so unless we're doing LTO or similar, it's body doesn't really matter. If LTO is running, then based on some local testing it looks like we pull in tons of code from std anyway (and backtrace etc) so it really doesn't matter whether we're using map_err or not.

I also want to avoid doing too much in this particular PR - makes it harder to compare things in perf, for example - so I am going to go ahead and @bors r=nagisa

@bors
Copy link
Contributor

bors commented Sep 16, 2021

📌 Commit db5ecd5 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 16, 2021
@bors
Copy link
Contributor

bors commented Sep 18, 2021

⌛ Testing commit db5ecd5 with merge 6cdd42f...

@bors
Copy link
Contributor

bors commented Sep 18, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 6cdd42f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 18, 2021
@bors bors merged commit 6cdd42f into rust-lang:master Sep 18, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 18, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6cdd42f): comparison url.

Summary: This change led to large relevant improvements 🎉 in compiler performance.

  • Large improvement in instruction counts (up to -4.4% on incr-full builds of helloworld)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants