Uh oh!
There was an error while loading. Please reload this page.
Simpler slice Iterator methods - #72166
Conversation
The default implementations of several `Iterator` methods use `fold` or `try_fold`, which works, but is overkill for slices and bloats the amount of LLVM IR generated and consequently hurts compile times. This commit adds the simple, obvious implementations for `for_each`, `all`, `any`, `find`, `find_map`, and simplifies the existing implementations for `position` and `rposition`. These changes reduce compile times significantly on some benchmarks.
Currently it uses `for x in self`, which seems dubious within an iterator method. Furthermore, `self.next()` is used in all the other iterator methods.
nnethercote
commented
May 13, 2020
@bors try @rust-timer queue |
rust-timer
commented
May 13, 2020
Awaiting bors try build completion |
bors
commented
May 13, 2020
⌛ Trying commit 3b10858 with merge 7f1659b19bed7255f86fa296721f74e5f107f9ef... |
bors
commented
May 13, 2020
☀️ Try build successful - checks-actions, checks-azure |
rust-timer
commented
May 13, 2020
Queued 7f1659b19bed7255f86fa296721f74e5f107f9ef with parent a2e0b48, future comparison URL. |
rust-timer
commented
May 13, 2020
Finished benchmarking try commit 7f1659b19bed7255f86fa296721f74e5f107f9ef, comparison URL. |
andjo403
commented
May 13, 2020
nice perf results
|
nnethercote
commented
May 13, 2020
It's a huge win for
The exact inlining is up to LLVM. The methods in
Maybe, maybe not. But if these functions are unnecessary, the cost of them remaining is small. In general, many optimizations for compile time involve trade-offs, adding complexity for speed. This one is no exception, but I feel that the extra complexity in this case is small relative to the speed improvements. Overall, I feel this optimization scores quite well on the speed-ups vs. complexity trade-off. |
andjo403
commented
May 14, 2020
what I was trying to ask was. as this change have inlined try_for in to this functions so this have already taken the decision away from LLVM so why stop there. only wondering if this will open the floodgate for PRs that changes inline functions to macros. also feel that there is a difference if it is a compiler change that makes a win for a few benchmarks or if it is a change in the std lib. but I agree overall this PR is not making the code more complex and there is good compile time speedups nice work as always and thanks for the answers. |
nnethercote
commented
May 15, 2020
I thought about doing a similar thing in other iterators, but can't see any suitable candidates. |
nnethercote
commented
May 15, 2020
cc @bluss |
cuviper
commented
May 16, 2020
Looks good! @bors r+ |
bors
commented
May 16, 2020
📌 Commit 3b10858 has been approved by |
Rollup of 7 pull requests Successful merges: - rust-lang#71625 (Improve the documentation for ManuallyDrop to resolve conflicting usage of terminology) - rust-lang#71919 (Update transitive dependency to work towards removing syn <1.0 dep) - rust-lang#72166 (Simpler slice `Iterator` methods) - rust-lang#72216 (Remove `lang_items\(\).*\.unwrap\(\)`) - rust-lang#72230 (Updated documentation of Prefix::VerbatimDisk) - rust-lang#72234 (Implement Default for proc_macro::TokenStream) - rust-lang#72258 (Fix typo Arbintrary to Arbitrary) Failed merges: r? @ghost
nnethercote
commented
May 19, 2020
Final perf results are here. This landed as part of a rollup because I forgot to mark it with |
These reduce the amount of LLVM IR generated, helping compile times.
r? @cuviper