WIP/RFC better map!(f, values(dict)) interface for AbstractDict #31362
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 is largely a continuation of #31223, but fleshes out a more generic interface for
map!(v,values(AdbstractDict))
. It aims to further cover some of the issues @chethega brought up in #31199. Right now it is focused on Dicts only but could be broadened to work with general Collections.As a preface I think everything will want to be renamed because the current descriptive names are a bit verbose, so say the least.... This preface is needed... well you will understand why.
The interface works by creating a trait with the function
DirectStyle(dict))
which needs to return one of the following:NaiveDict()
for the worst case naive implimentationSlottedDict
Which is fo dicts that are structured likeDict
with slots . This will cover most important implimentations.PointerDict
Which has an iterate like function that function which returns 0-Dim arrays to the value for modification.Compared to the previous
map!(f,values(dict::Dict))
the SlottedDict path is able to be generic with only a 10% loss in performance.Right now the performance follows the trend
NaiveDict ---(is 3x slower than)--->PointerDict----(is 6x slower than)--> SlottedDict
With a little bit of tuning, I think that
PointerDict
has the potential to be as fast asSlottedDict
I just haven't figure out why the optimizer isn't getting it there. Right now it isPointerDict
is roughly as fast as theValueIterator
.A real implimentation is included for
Dict
whileWeakKeyDict
has a example ofPointerDict
that would be changed before final release.The definition of the iterface can be a little helpfully in understand but is very much a WIP:
(Please forgive all the
Base.
they are there to make hacking outside of base easier)