Proposed Changes to the Range API for Phobos v3
Steven Schveighoffer
schveiguy at gmail.com
Tue Sep 24 15:26:39 UTC 2024
On Tuesday, 24 September 2024 at 14:36:05 UTC, Steven
Schveighoffer wrote:
> Results:
> ```
> opApplyRange took 186 ms, 123 μs, and 9 hnsecs for 100 runs
> phobosRange took 1 sec, 345 ms, 67 μs, and 5 hnsecs for 100 runs
> newRangeStyle took 83 ms, 706 μs, and 2 hnsecs for 100 runs
> simpleRanges took 136 ms and 47 μs for 100 runs
> ```
>
> Interestingly here, the simple ranges seem properly inlined. So
> somehow the optimizer could see through those despite having 3
> function API, but not the normal ranges? Is there something I
> did special in there that the normal functions prevent?
Some more info, my simple filter range pre-computes the first
element, and then avoids the whole "check if it's initialized"
dance on `front` and `empty`.
If I add that "feature" to my range, it gets a lot slower, like
5x slower. Still not as bad as Phobos, but it explains a bit of
it.
This is the cost of "optimizing" ranges just in case someone does
something unexpected.
Oh, and someone asked on discord, I am using `-O3` on the build.
-Steve
More information about the Digitalmars-d
mailing list