-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Simpler slice Iterator
methods
#72166
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.
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 3b10858 with merge 7f1659b19bed7255f86fa296721f74e5f107f9ef... |
☀️ Try build successful - checks-actions, checks-azure |
Queued 7f1659b19bed7255f86fa296721f74e5f107f9ef with parent a2e0b48, future comparison URL. |
Finished benchmarking try commit 7f1659b19bed7255f86fa296721f74e5f107f9ef, comparison URL. |
nice perf results
|
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. |
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. |
I thought about doing a similar thing in other iterators, but can't see any suitable candidates. |
cc @bluss |
Looks good! @bors r+ |
📌 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
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