Bug 12446 – std.parallelism.amap prefer iteration to indexing
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-23T13:36:00Z
Last change time
2014-03-23T21:17:38Z
Keywords
pull
Assigned to
safety0ff.bugz
Creator
safety0ff.bugz
Comments
Comment #0 by safety0ff.bugz — 2014-03-23T13:36:07Z
Currently std.parallelism.amap uses the random access range primitives instead of the input range primitives to traverse the per-thread slices.
This matters when random access is more expensive than iteration.
Iteration, if properly implemented, should always at least as fast as indexing.
Comment #1 by safety0ff.bugz — 2014-03-23T13:54:09Z
(In reply to comment #0)
> This matters when random access is more expensive than iteration.
>
> Iteration, if properly implemented, should always at least as fast as indexing.
It occurred to me that the cost of slicing a range could be disproportionate to indexing. Are there any use cases where this is true?
Comment #2 by safety0ff.bugz — 2014-03-23T14:37:56Z
I think the differences should be negligible among the two approaches.
Comment #4 by andrei — 2014-03-23T14:55:56Z
... But there's always a way to test by measuring :o). Try it on a few typical ranges. ("Typical" == cost of random access, if offered, shouldn't be onerous.)
Comment #5 by safety0ff.bugz — 2014-03-23T15:26:51Z
(In reply to comment #4)
> ... But there's always a way to test by measuring :o). Try it on a few typical
> ranges. ("Typical" == cost of random access, if offered, shouldn't be onerous.)
It's not typical array-like random access ranges that will benefit, it's atypical ones where iteration is simple but indexing is non-trivial.
For example, my "triangular" random access range which returns the tuples:
[0, 0], [1, 0], [1, 1], [2, 0], [2, 1], [2, 2], [3, 0], [3, 1], [3, 2], [3, 3]
Iteration is simple, but indexing involves solving a quadratic + some other operations.
Even though one might not call this "onerous," there is still enough relative difference for it to be noticeable.
Comment #6 by github-bugzilla — 2014-03-23T16:00:39Z