-
Notifications
You must be signed in to change notification settings - Fork 38
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
Specialize iterate
#181
Specialize iterate
#181
Conversation
Codecov Report
@@ Coverage Diff @@
## master #181 +/- ##
=======================================
Coverage 96.94% 96.95%
=======================================
Files 4 4
Lines 655 657 +2
=======================================
+ Hits 635 637 +2
Misses 20 20
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -121,7 +121,7 @@ Fill{T,0}(x::T, ::Tuple{}) where T = Fill{T,0,Tuple{}}(x, ()) # ambiguity fix | |||
@inline Fill{T,N,Axes}(F::Fill{T,N,Axes}) where {T,N,Axes} = F | |||
|
|||
@inline axes(F::Fill) = F.axes | |||
@inline size(F::Fill) = length.(F.axes) | |||
@inline size(F::Fill) = map(length, F.axes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change helps in cases where types aren't inferred:
julia> x = (1:3, 1:3); y = Any[x];
julia> @btime (x -> map(length, x[1]))($y);
23.936 ns (1 allocation: 32 bytes)
julia> @btime (x -> length.(x[1]))($y);
367.806 ns (3 allocations: 128 bytes)
Gentle bump @dlfivefifty |
1 similar comment
Gentle bump @dlfivefifty |
For the record, this performance match is obtained on v1.9. The performance is still somewhat inferior on v1.8. julia> x = Fill(2, 300, 300);
julia> @benchmark [i for i in $x]
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 60.455 μs … 1.435 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 68.263 μs ┊ GC (median): 0.00%
Time (mean ± σ): 75.443 μs ± 41.992 μs ┊ GC (mean ± σ): 6.53% ± 10.20%
▅█▅▃▂▁▁ ▁
██████████▇▆▅▅▆▆▄▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▄▅▇▇ █
60.5 μs Histogram: log(frequency) by time 375 μs <
Memory estimate: 703.17 KiB, allocs estimate: 2.
julia> @benchmark fill(2, 300, 300)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 59.974 μs … 715.494 μs ┊ GC (min … max): 0.00% … 90.87%
Time (median): 69.090 μs ┊ GC (median): 0.00%
Time (mean ± σ): 79.698 μs ± 62.497 μs ┊ GC (mean ± σ): 9.81% ± 10.92%
▇█▄▃▂▂▁ ▂
█████████▇▄▄▃▃▄▄▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▆▇▇ █
60 μs Histogram: log(frequency) by time 552 μs <
Memory estimate: 703.17 KiB, allocs estimate: 2. On Julia v1.8: julia> @benchmark fill(2, 300, 300)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 58.523 μs … 576.305 μs ┊ GC (min … max): 0.00% … 55.65%
Time (median): 68.670 μs ┊ GC (median): 0.00%
Time (mean ± σ): 76.727 μs ± 40.618 μs ┊ GC (mean ± σ): 6.07% ± 10.07%
▂██▅▄▃▂▁▁ ▂
███████████▇▇▆▅▄▃▄▄▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▄▄▄▅▆▆▅▆▅▃▄▃▄▁▁▁▁▁▁▁▁▁▄▅▇█ █
58.5 μs Histogram: log(frequency) by time 358 μs <
Memory estimate: 703.17 KiB, allocs estimate: 2.
julia> @benchmark [i for i in $x]
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 67.364 μs … 2.151 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 75.189 μs ┊ GC (median): 0.00%
Time (mean ± σ): 86.099 μs ± 65.544 μs ┊ GC (mean ± σ): 8.51% ± 10.57%
█▇▄▂▁ ▂
██████▇▇▆▅▄▄▅▄▁▁▃▃▁▁▁▁▁▁▁▁▃▁▅▆▇▆▆▄▁▁▁▃▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▃▆▇▇ █
67.4 μs Histogram: log(frequency) by time 537 μs <
Memory estimate: 703.17 KiB, allocs estimate: 2. |
On master:
This PR makes them both equally fast:
I've also removed some specializations of
sum
, as the specializedBase._mapreduce_dim
covers these. On this PR: