Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upThe new step_by is too much slow #43064
Comments
leonardo-m
referenced this issue
Jul 5, 2017
Merged
Delete deprecated & unstable range-specific `step_by` #43012
bstrie
added
I-slow
T-libs
labels
Jul 5, 2017
SimonSapin
referenced this issue
Jul 5, 2017
Merged
Implement O(1)-time Iterator::nth for Range*, and slim the Step trait #43077
bors
added a commit
that referenced
this issue
Jul 8, 2017
bors
closed this
in
#43077
Jul 8, 2017
This comment has been minimized.
This comment has been minimized.
|
Dear bors, before closing down this issue you should show me that the asm after that pull request is good enough. I'll verify it myself tomorrow with the next Nightly. |
This comment has been minimized.
This comment has been minimized.
|
Technically this is closed by GitHub not bors |
This comment has been minimized.
This comment has been minimized.
|
Reopening so we track verification. |
Mark-Simulacrum
reopened this
Jul 8, 2017
SimonSapin
referenced this issue
Jul 8, 2017
Closed
Redesign the std::iter::Step trait, tweak related iterator impls for ranges #43127
This comment has been minimized.
This comment has been minimized.
|
The asm now is:
Ti me it looks still too much long. And apparently there's a call to a TryFrom in the middle of the loop... In some of my code I see a further 10% performance decrease after the recent performance decrease caused by allocators. |
This comment has been minimized.
This comment has been minimized.
|
I pretty much can’t read assembly. Is either the before or after code O(n) for The call to I have more changes to this code in #43127 |
This comment has been minimized.
This comment has been minimized.
I think it's now O(1), but the asm is a bit of a mess. step_by() is part of the basics of for loops in Rust, a system language. So before pull requests about it got merged, someone that knows assembly should carefully review the code.
So having only usize as step_by argument causes problems. Perhaps it's not a good idea. step_by() is meant to be used everywhere, its inner loop will run trillions of times. Perhaps all changes to step_by of the last few weeks should be reverted, and merged again only if and when they are acceptable. |
This comment has been minimized.
This comment has been minimized.
Doing this kind of experiment and finding problems is the point of having a Nightly channel. |
This comment has been minimized.
This comment has been minimized.
This looks like it's an issue with TryFrom/TryInto rather than step_by itself. EDIT: The main difference seems to be the overflow checks. |
oyvindln
referenced this issue
Jul 12, 2017
Closed
Add inline annotations and avoid 128-bit where it's not needed in TryFrom + tests for xsize/x128 #43194
This comment has been minimized.
This comment has been minimized.
|
In addition to the overflow checks, there is a check in the Additionally, there is a call to try_from that isn't optimized out, but #43194 should help with that. The overflow checks are probably the main issue though, so having a specialisation of this trait for ranges would probably be helpful. |
Mark-Simulacrum
added
the
C-enhancement
label
Jul 26, 2017
This comment has been minimized.
This comment has been minimized.
|
I had a go at adding specializations for the primitive types, however, that triggered #36262, which made the compiler treat range syntax without type annotations (e.g 0...50) as always being i32 rather than inferring the type. I Also tried to specialize using the Step trait, however I didn't manage to it to work as adding default to |
This comment has been minimized.
This comment has been minimized.
|
To better show the effects of the new step_by here you can find a test program (that solves two different Euler problems) that uses step_by (run-time 4.40 seconds): And the same code with step_by replaced by while loops (run-time 3.81 seconds): |
leonardo-m
referenced this issue
Jan 6, 2018
Closed
Tracking issue for `step_by` stabilization #27741
This comment has been minimized.
This comment has been minimized.
|
@oyvindln Nice experiment (I'd love to see the code). I think the associated type defaults issue is expected, and it seems best to avoid using associated type specialization for now, even in std. |
This comment has been minimized.
This comment has been minimized.
|
@bluss Didn't find any code from trying to specialize using the step trait. |
bors
added a commit
that referenced
this issue
Jun 21, 2018
This comment has been minimized.
This comment has been minimized.
|
Since few days the step_by is fast enough for my usages, so I close this issue down (I still don't like the design of the new step_by that only works with usize steps, but I guess I can't change that). I leave Issue #45222 open because closed intervals are still too much slow. |
leonardo-m commentedJul 5, 2017
As I explained in #42534 the new step_by can't be used:
Compiling with:
rustc -O --emit asm test.rs
It gives:
In a function like second_foo() the old step_by gave something like: