FillArrays.jl
FillArrays.jl copied to clipboard
Specialize `iterate`
On master:
julia> @btime fill(2, 300, 300);
61.167 μs (2 allocations: 703.17 KiB)
julia> x = Fill(2, 300, 300);
julia> @btime [i for i in $x];
77.769 μs (2 allocations: 703.17 KiB)
This PR makes them both equally fast:
julia> @btime [i for i in $x];
60.280 μs (2 allocations: 703.17 KiB)
I've also removed some specializations of sum, as the specialized Base._mapreduce_dim covers these. On this PR:
julia> @btime sum(x->x^2, $x);
3.355 ns (0 allocations: 0 bytes)
julia> @btime sum($x);
3.358 ns (0 allocations: 0 bytes)
Codecov Report
Merging #181 (f6f0fd0) into master (d04c596) will increase coverage by
0.00%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #181 +/- ##
=======================================
Coverage 96.94% 96.95%
=======================================
Files 4 4
Lines 655 657 +2
=======================================
+ Hits 635 637 +2
Misses 20 20
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/FillArrays.jl | 95.57% <100.00%> (+0.02%) |
:arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
Gentle bump @dlfivefifty
Gentle bump @dlfivefifty
For the record, this performance match is obtained on v1.9. The performance is still somewhat inferior on v1.8. On v1.9
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.