-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
WIP: The great pairwise reduction refactor #58418
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
base: master
Are you sure you want to change the base?
The head ref may contain hidden characters: "mb/ReduceReuse\u267B"
Changes from all commits
80f031f
3c3fdcc
4baecd3
93796ab
0c3d4b2
0a3f844
19f0ebb
0708c2b
e719715
da3bdb1
8cef637
89c3975
f88cfeb
bddc126
7747f1e
31de628
2f5a886
aeb9a89
2a0b7b7
6cc2496
ec3def4
7445ccd
eed76db
ed4cd1b
cfe80cd
aab7aa3
cf551b1
1748ff4
febc5ee
84e3711
8b8fd7c
133e960
5fdb54c
e013f9f
6fb8ef1
167888d
a093f9d
be75442
a6e4e73
744e3fd
647d5ed
6fb57cc
07e11a2
144c253
ddc4502
30c8afb
b66af55
a729ea7
13ee1b5
e6948ec
8ec7b41
427bbb7
5f8c6a3
cdb3cb4
264b8db
3d5cfec
4807a12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -846,7 +846,15 @@ function iterate(d::ImmutableDict{K,V}, t=d) where {K, V} | |
!isdefined(t, :parent) && return nothing | ||
(Pair{K,V}(t.key, t.value), t.parent) | ||
end | ||
length(t::ImmutableDict) = count(Returns(true), t) | ||
# length is defined in terms of iteration; using a higher-order function to do the iteration | ||
# is likely to call `length` again, so this is a manual for loop: | ||
function length(t::ImmutableDict) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't this be horribly slow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, wasn't it already doing this? This shouldn't be any worse. It's definitely faster than infinite recursion :) The trouble is that On nightly: julia> using BenchmarkTools
julia> d = Base.ImmutableDict((i => i+1 for i in 1:200)...);
julia> @benchmark length($d)
BenchmarkTools.Trial: 10000 samples with 641 evaluations per sample.
Range (min … max): 193.512 ns … 392.225 ns ┊ GC (min … max): 0.00% … 0.00%
Time (median): 193.772 ns ┊ GC (median): 0.00%
Time (mean ± σ): 196.869 ns ± 11.655 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
█▁ ▁▃▂▄▂ ▁
███████████▇██▇▇▆▇▆▆▆▅▅▇▆▆▅▆▅▅▆▅▅▅▅▅▅▅▄▄▅▅▅▅▂▄▃▃▄▄▄▄▃▂▂▂▃▄▂▅▄ █
194 ns Histogram: log(frequency) by time 241 ns <
Memory estimate: 0 bytes, allocs estimate: 0.
julia> @eval Base function length(t::ImmutableDict)
r = 0
for _ in t
r+=1
end
return r
end
length (generic function with 95 methods)
julia> @benchmark length($d)
BenchmarkTools.Trial: 10000 samples with 631 evaluations per sample.
Range (min … max): 193.542 ns … 366.482 ns ┊ GC (min … max): 0.00% … 0.00%
Time (median): 193.740 ns ┊ GC (median): 0.00%
Time (mean ± σ): 196.829 ns ± 11.533 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
█ ▁ ▄ ▂ ▁
███████▇███▇██▇▇▇▇▆▇▆▆▅▆▆▆▇▆▆▆▅▅▅▅▅▅▄▅▆▅▄▅▅▅▅▄▄▅▄▄▄▅▅▄▄▃▄▄▃▃▄ █
194 ns Histogram: log(frequency) by time 238 ns <
Memory estimate: 0 bytes, allocs estimate: 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah that's unfortunate... |
||
r = 0 | ||
for _ in t | ||
r+=1 | ||
end | ||
return r | ||
end | ||
isempty(t::ImmutableDict) = !isdefined(t, :parent) | ||
empty(::ImmutableDict, ::Type{K}, ::Type{V}) where {K, V} = ImmutableDict{K,V}() | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.