Skip to content

from_array performance when no name is provided #3946

Closed

Description

@hmaarrfk

The performance of from_array seems to be seriously affected when no name is provided.

I understand that in the documentation you mention that setting name to false is (fast), but I think the default should be changed to False. Edit: I think perhaps a more stark warning should be provided and the information that @martindurant can be linked in the comment.

For example, the asarray function doesn't even provide a name argument. this means that using asarray is guaranteed to be slow. da.asarray is used in at least a few places like empty_like which make that function take for ever....

I have a feeling the whole array module will feel different with that default changed

from dask import array as da
import numpy as np
import dask
print(dask.__version__)
print(np.__version__)
# For python to load up dask array for fair benchmarks
_ = da.asarray(np.zeros(2))
shape = (50, 1024, 1024)

# This takes Wall time 170 ms
%time a = np.ones(shape=shape)
# This takes wall time 500 ms!!
%time _ = da.asarray(a) 
# This takes wall time 400 us, that is more like it!
%time _ = da.from_array(a, chunks=-1, name=False)
# This takes 500 ms !!!
%time b = da.from_array(a, chunks=-1)

# This takes 500ms!!
%time da.empty_like(a)
# This takes 100 us! much more like it
%time da.empty_like(b)

Activity

  1. mrocklin commented on Sep 5, 2018

    @mrocklin
    Member

    but I think the default should be changed to False.

    Defaults are tricky things. They need to be optimized over many different use cases. Splitting large in-memory numpy arrays into a dask arrays is actually a pretty rare workload overall. More often large dask arrays come into being from being loaded directly from files/network or are otherwise generated in a way where we can create their name without hashing all of their data (filename, last modification time, etc..) However when these arrays interact with Numpy arrays those numpy arrays are more often quite small, and hashing them by default to avoid repeated work in complex algorithms is a very useful feature that can significantly improve performance.

    The cost to people accelerating Numpy workloads is unfortunate. I don't disagree that it would be good to avoid this somehow, but based on current use it's not clear that changing the default is strictly a good idea.

  2. hmaarrfk commented on Sep 5, 2018

    @hmaarrfk
    ContributorAuthor
  3. martindurant commented on Sep 5, 2018

    @martindurant
    Member

    It is worth pointing out that for arrays, the default hash uses python's standard sha1, but if you happen to have cityhash, xxhash or murmurhash installed (all available with pip), then you can get a large-factor speedup in the tokenisation step. You may consider that a separate point, but perhaps it is useful.

  4. mrocklin commented on Sep 5, 2018

    @mrocklin
    Member

    Adding a name parameter makes sense.

  5. hmaarrfk commented on Sep 5, 2018

    @hmaarrfk
    ContributorAuthor

    I guess that will start to depart from the numpy API.

    Seem like you could:

    1. Add a name parameter to asarray
    2. Make asarray call from_array with name=False

    I'm not sure if that will invoke the same loss in hashing for the algorithms you mentioned.

  6. hmaarrfk commented on Sep 8, 2018

    @hmaarrfk
    ContributorAuthor

    @mrocklin I could add a PR to add a name parameter to asarray.

    How would this affect the performance of *_like when calling asarray with the parameter name=False for the use cases you mentioned?

  7. mrocklin commented on Sep 9, 2018

    @mrocklin
    Member
  8. hmaarrfk commented on Sep 9, 2018

    @hmaarrfk
    ContributorAuthor

    So the added parameter should have to be added to the functions *_like as well?

  9. mrocklin commented on Sep 9, 2018

    @mrocklin
    Member
  10. jakirkham commented on Sep 9, 2018

    @jakirkham
    Member

    FYI the *_like functions don't actually generate any arrays until computation occurs. So hashing for them proceeds through a different path. Doubt that adding a name parameter is needed in that case.

  11. mrocklin commented on Sep 9, 2018

    @mrocklin
    Member
  12. mrocklin commented on Sep 9, 2018

    @mrocklin
    Member
  13. jakirkham commented on Sep 9, 2018

    @jakirkham
    Member

    For the asarray checks in those functions? That sounds like a good idea. Alternatively we could rely completely on duck typing there and drop the asarray calls. That may cause some breakage for users relying on asarray to be called for them, but we could mitigate this with a decent exception message and users can fix the issue pretty easily.

  14. hmaarrfk commented on Sep 9, 2018

    @hmaarrfk
    ContributorAuthor

    the only thing I can think of is:

    import dask.array as da
    a = [[1, 2], [3, 4]]
    da.empty_like(a)
    

    doesn't have the array interface.

    we would need a function that is like:

    def get_size_and_dtype(a):
        check if it has the array protocol,
        else
            da.from_array(a, name=False)
    
  15. hmaarrfk commented on Oct 23, 2018

    @hmaarrfk
    ContributorAuthor

    Thanks @mrocklin !!

  16. mrocklin commented on Oct 23, 2018

    @mrocklin
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions