Skip to content

Inside Rust: Add "Exploring PGO for the Rust compiler" blog post. #718

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

Merged

Conversation

michaelwoerister
Copy link
Member

This is a blog post about the effects that profile-guided optimization has on rustc's performance. It might be of interest to members of @rust-lang/infra, @rust-lang/release, @rust-lang/compiler, and @rust-lang/compiler-contributors.

r? @pnkfelix

@michaelwoerister michaelwoerister requested a review from a team October 28, 2020 11:58
@michaelwoerister michaelwoerister requested a review from a team as a code owner October 28, 2020 11:58
@XAMPPRocky
Copy link
Member

XAMPPRocky commented Oct 28, 2020

Rendered (w/o images)


[![Performance improvements gained from apply PGO to LLVM][rustc-perf-pgo-llvm-thumb]][rustc-perf-pgo-llvm]
[rustc-perf-pgo-llvm-thumb]: /images/inside-rust/2020-10-30-exploring-pgo-for-the-rust-compiler/rustc-perf-pgo-llvm-thumb.png
[rustc-perf-pgo-llvm]: /images/inside-rust/2020-10-30-exploring-pgo-for-the-rust-compiler/rustc-perf-pgo-llvm.png
Copy link
Member

Choose a reason for hiding this comment

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

FWIW I'd be willing to work with you if you have the time to try and get these results on perf.rust-lang.org (even if they're not collected by the official collector), it should be possible to import them. Let me know.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could send you the results.db. Would that help?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it shouldn't be too hard to pull results from there and into the postgres db used by the official backend, which would mean that we can provide URLs here rather than pulling images (which should be all around nicer I imagine).

I expect to name the artifacts e.g. "pgo-llvm" as you've done here fwiw.

Comment on lines 281 to 282
Rust's CI build times have always been too long and we already forgo some optimizations because of them
(e.g. macOS still does not get the 10% performance boost from using a ThinLTOed LLVM because the build machines on that platform are especially slow).
Copy link
Member

Choose a reason for hiding this comment

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

Do we currently use LTO on the compiler itself? I couldn't find anything in config.toml or any of the Cargo.toml files. That might be an easy start to this, running LTO on only the stable and beta channels without having to mess with the new PGO build system yet.

Copy link
Member

Choose a reason for hiding this comment

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

LLVM (used to be) ThinLTOd on x86_64-unknown-linux-gnu, see rust-lang/rust#78148 and linked issues/PRs for details. It wasn't a big loss to disable it (3-4% IIRC).

Copy link
Member

Choose a reason for hiding this comment

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

Right - did we ever run LTO on the rust code though (as separate from LLVM)?

Copy link
Member

Choose a reason for hiding this comment

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

Rust code I think is always ThinLTOd, though I might be misremembering. I don't recall if we've tried full LTO though. It should be relatively easy to try.

Copy link
Member Author

Choose a reason for hiding this comment

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

LLVM (used to be) ThinLTOd on x86_64-unknown-linux-gnu, see rust-lang/rust#78148 and linked issues/PRs for details. It wasn't a big loss to disable it (3-4% IIRC).

Interesting. I saw a bigger impact recently (~10% instruction count reduction, I think). I'll take another look.

@jyn514 jyn514 added the content An issue related to an article. label Oct 28, 2020
adding newlines as suggested by @jyn514 to resolve image display issue.

Co-authored-by: Joshua Nelson <[email protected]>
@pnkfelix
Copy link
Member

Looks great to me. I dont think I have r+ privileges on this repo, though! :)

@Mark-Simulacrum
Copy link
Member

I am inclined to merge this but want to hear back from @michaelwoerister on the upstreaming of the results (since that would give a nicer UI here). It's scheduled for the 30th as well anyway.

@Mark-Simulacrum
Copy link
Member

I hope to get to the uploading this week, it shouldn't be too much work and I just need to sit down and do it :)

@michaelwoerister
Copy link
Member Author

OK, the post is done now, with links pointing to perf.rlo instead of static images (thanks to @Mark-Simulacrum). The only thing that might need fixing is the publishing date (which is still Oct 30). What date should I put there? Nov 12 maybe?

@Mark-Simulacrum
Copy link
Member

November 12th sounds fine, or we can do today. Just give me a ping on Zulip when the date is updated (whichever you choose).

@Mark-Simulacrum Mark-Simulacrum merged commit 1a8abd2 into rust-lang:master Nov 11, 2020
@chadbrewbaker
Copy link

Would rebuilding just https://packages.debian.org/sid/lld-11 (why not libc/libc++ too and static link for the heck of it) with PGO be enough on the LLVM side for most of the performance gain?

Also, https://github.com/llvm/llvm-project has a cmake configure that takes an entire minute on my box. Might save some time by caching parts of it you know that won't change. Cmake itself needs a re-write to allow parallelism in the language - if not coding the non-performant parts in C++/rust instead of interpreting them as scripts.

@bjorn3
Copy link
Member

bjorn3 commented Nov 12, 2020

https://packages.debian.org/sid/lld-11 is just for the lld linker, not for libLLVM.so. Rustc doesn't use lld by default yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content An issue related to an article.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants