OrderedDict: improve performance for non-concrete values and keys#166
Conversation
timholy
left a comment
There was a problem hiding this comment.
Sad to see more rather than fewer @inbounds annotations but the performance gain is compelling.
One optional tweak. Good to go once you decide how you want to proceed.
| function iterate(t::OrderedDict{K,V}) where {K,V} | ||
| t.ndel > 0 && rehash!(t) | ||
| length(t.keys) < 1 && return nothing | ||
| return (Pair(t.keys[1], t.vals[1]), 2) |
There was a problem hiding this comment.
I know you're just copying what was already there, but I wonder about switching to first and similarly checkbounds(Bool, t.keys, i) for the i-generic one; those are more precisely aligned to what's actually being tested. It's the same thing for Vector, of course. Up to you, I'd merge this without that change.
There was a problem hiding this comment.
I'd rather minimize the diff in this PR to focus on the specifics that changed the behavior.
Most (pretty much all) perf comes from the type of the |
Using the following benchmark
I get:
This mirrors how Base does it https://github.com/JuliaLang/julia/blob/3e1bf51ccd6f5cb8a547ca99d0fd33de24ac85e8/base/dict.jl#L701