Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR speeds up
mergewith!in two ways:mergewith!makes it operate faster if the additional dictionaries use different types. As an added bonus, one now needs to implement dedicatedmergewith!methods only for merging exactly two dictionaries.The following table shows the speed-up factor for merging an
IdDict{Int,Float64}and anIdDict{Int, Int}into anIdDict{Int,Float64}. "Partial overlap" means that the dictionaries have half of the keys in common.I'm comparing to Julia 1.6.1. Because of the second change, I'm not using
Dicthere.Dictis added.The following table shows the speed-up factor for
Dict{Int,Int}compared to the existing generic implementation forAbstractDict. The new method appears to be always faster, for dictionaries with less than 600 elements usually by a factor of at least 2.Both changes combined lead to the following speed-up for merging a
Dict{Int,Float64}and aDict{Int,Int}into aDict{Int,Float64}:Click here for the code used to obtain the timings
Some more comments:
ageparameter forDict. My understanding is that this is not necessary if only existing values are modified. (For new entries this is done inside_setindex!.)mergewith!is already extensively tested withDictintest/dict.jl. These test sets now call the new dedicated function. I have added tests for theAbstractDictmethod totest/dict.jl; they useIdDict.