-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Fix Int overrun potential in dict skip_deleted #31452
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
Fix Int overrun potential in dict skip_deleted #31452
Conversation
|
Any speedup is nice of course, but do I understand right that this is guarding against arrays of length |
Problem is that LLVM goes and proves an overflow and then decides that this loop is not worthy of future optimization. |
|
LLVM never seems to clone loop for this purpose. Even though it almost always emit the scalar loop anyway. Saw this for both overflow problem and alignment.... |
|
@JeffBezanson some relevant discussion happened in #31416. For me this is for the burndown of a list of things that could get into the way of higher level iterators getting in the way of being really lean loops. In digging into that and trying to understanding what stopped fast loops from being emitted this showed up and I thought it should just be fixed while still top of mind. |
|
A more poweful benchmark might be this using BenchmarkTools
d=Dict(v=>v for v in 1:1000)
function for_sum(f,iter)
ret=0
for v in iter
ret += f(v)
end
return ret
end
function while_sum(f,iter)
ret=0
next = iterate(iter)
while next !== nothing
(v, state) = next
ret+=f(v)
next = iterate(iter, state)
end
return ret
endBefore: julia> @benchmark for_sum(v->v,values(d))
BenchmarkTools.Trial:
memory estimate: 32 bytes
allocs estimate: 2
--------------
minimum time: 6.816 μs (0.00% GC)
median time: 7.893 μs (0.00% GC)
mean time: 9.323 μs (0.00% GC)
maximum time: 294.384 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 4
julia> @benchmark while_sum(v->v,values(d))
BenchmarkTools.Trial:
memory estimate: 32 bytes
allocs estimate: 2
--------------
minimum time: 5.534 μs (0.00% GC)
median time: 6.920 μs (0.00% GC)
mean time: 8.478 μs (0.00% GC)
maximum time: 544.237 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 5
after: julia> @benchmark for_sum(v->v,values(d))
BenchmarkTools.Trial:
memory estimate: 32 bytes
allocs estimate: 2
--------------
minimum time: 3.461 μs (0.00% GC)
median time: 4.886 μs (0.00% GC)
mean time: 5.145 μs (0.00% GC)
maximum time: 176.057 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 8
julia> @benchmark while_sum(v->v,values(d))
BenchmarkTools.Trial:
memory estimate: 32 bytes
allocs estimate: 2
--------------
minimum time: 3.501 μs (0.00% GC)
median time: 3.723 μs (0.00% GC)
mean time: 4.421 μs (0.00% GC)
maximum time: 127.837 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 8These benchmark tailored to be like use in the wild. |
|
This provides a good performance bump is there anything that is blocking? |
|
Thanks for explaining. Nice work! |
Previously there was the potential for an infinite loop in the
skip_deletedfunction inL=typemax(Int). This fixes that and provides some performance benefits.Baseline:
After fix: