Repository navigation
add numpy array of dask keys to Array - #7922
Merged
Merged
Conversation
jsignell
reviewed
Jul 21, 2021
jsignell
left a comment
Member
There was a problem hiding this comment.
This approach seems good, but I think you will want to explicitly reset the cache when name or the chunks changes. There is a method called _reset_cache for that.
Member
Author
|
There weren't any tests ensuring that these cached array properties get reset after a change of chunks, so I added one. |
jsignell
reviewed
Jul 22, 2021
jsignell
left a comment
Member
There was a problem hiding this comment.
This is looking really nice! My last comments are:
- maybe we should prefix the property with an underscore to denote that it's private
- I still think that when the name is set the key_array needs to be reset. Here:
Lines 1486 to 1490 in 56d1891
Member
Author
|
I still need to add tests for the cache invalidation after name change. |
Member
|
It seems like this is just missing a few tests @d-v-b when you get a chance :) |
d-v-b
force-pushed
the
cached-array-of-keys
branch
from
October 8, 2021 16:30
99fd20f to
adcf354
Compare
Member
Author
|
@jsignell thanks for the nudge, I added the missing test :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Array.blocksperformance #7832black dask/flake8 dask/isort daskThis PR adds the cached
key_arrayproperty to theArrayclass. This property is just a cached numpy array of theArray.__dask_keys__()property withdtype=object. Adding this as a property of theArrayclass allows me to remove expensive numpy array creation inArray._blocksand thereby make iterating overArray.blocksmore performant.I benchmarked iteration over
Array.blockswith the following code:Running this benchmark on main takes 17.60s; with the changes in this PR, the benchmark takes 4.58s.
As mentioned in #7832, another solution to this problem would be to implement the numpy array slicing interface for the
Array.__dask_keys__property. This might be a better approach (I don't like adding properties just to enhance performance of one method), but it would be much more work and require more test coverage (unless there's an existing test suite for "adapt numpy array slicing to lists-of-lists"). Additionally, the approach I took in this PR will organically track any changes in the numpy array slicing interface. But maybe that interface changes too slowly for this to be valuable.edit: update that tests were added