-
Notifications
You must be signed in to change notification settings - Fork 292
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 closures to improve compile times. #183
Conversation
Here are some measurements from my Linux box, measuring
|
`HashMap` and `HashSet` are used widely, and often instantiated many times. As a result, small differences in how the code is written can have a significant effect on how much LLVM IR is generated, which affects compile times. This commit avoids a lot of small closures by replacing calls to `Option::map`, `Option::ok_or_else`, `Option::unwrap_or_else` and `Result::unwrap_or_else` with `match` expressions. Although this makes the code less concise, it improves compile times. For example, several of the benchmarks in rustc-perf compile up to 3.5% faster after this change is incorporated into std. Every change is accompanied by a short comment to explain why a `match` is used. This may seem excessive, but without these comments it would be easy for a well-meaning person in the future to change some or all of these back to the original versions without understanding the consequences.
7d359d7
to
e47bec1
Compare
@bors r+ |
📌 Commit e47bec1 has been approved by |
☀️ Test successful - checks-travis |
@Amanieu: I know that hashbrown was just upgraded in std to 0.8.1, but I think it would be worth doing a 0.8.2 release with this change so that the compile time benefits can be spread widely? |
Sure, I'll do that after #184 is merged. |
Update hashbrown to 0.8.2 Includes: - Avoid closures to improve compile times (rust-lang/hashbrown#183) - Do not iterate to drop if empty (rust-lang/hashbrown#182) r? @Mark-Simulacrum
Port of the relevant changes from hashbrown from rust-lang/hashbrown#183
We manually expand these to reduce the amount of LLVM IR generated. (rust-lang#183)
Allow clippy::manual_map We manually expand these to reduce the amount of LLVM IR generated. (#183)
HashMap
andHashSet
are used widely, and often instantiated manytimes. As a result, small differences in how the code is written can
have a significant effect on how much LLVM IR is generated, which
affects compile times.
This commit avoids a lot of small closures by replacing calls to
Option::map
,Option::ok_or_else
,Option::unwrap_or_else
andResult::
unwrap_or_elsewith
match` expressions. Although this makesthe code less concise, it improves compile times. For example, several
of the benchmarks in rustc-perf compile up to 3.5% faster after this
change is incorporated into std.
Every change is accompanied by a short comment to explain why a
match
is used. This may seem excessive, but without these comments it would be
easy for a well-meaning person in the future to change some or all of
these back to the original versions without understanding the
consequences.