Skip to content

Use ensure_dict in _optimize_insert_futures - #2594

Merged
mrocklin merged 1 commit into
dask:masterfrom
jrbourbeau:use_ensure_dict
Apr 4, 2019
Merged

mrocklin merged 1 commit into
dask:masterfrom
jrbourbeau:use_ensure_dict

Conversation

@jrbourbeau

Copy link
Copy Markdown
Member

This PR updates _optimize_insert_futures to use dask.utils.ensure_dict instead of the built-in dict constructor when converting a dask graph to a dictionary.

Both dask.utils.ensure_dict and dict will produce the same output, but dask.utils.ensure_dict is faster when dealing with large HighLevelGraphs for dask collections with lots of chunks / partitions.

For example:

In [1]: import dask

In [2]: import dask.array as da

In [3]: a = da.random.randint(0, 100, size=200_000, chunks=1)

In [4]: # Add additional layers to the underlying HighLevelGraph
   ...: a = a + 1
   ...: a = a * 2

In [5]: len(a.dask)
Out[5]: 600000

In [6]: %timeit -n 1 dict(a.dask)
1.43 s ± 60.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [7]: %timeit -n 1 dask.utils.ensure_dict(a.dask)
272 ms ± 11.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [8]: dict(a.dask) == dask.utils.ensure_dict(a.dask)
Out[8]: True

@jrbourbeau

Copy link
Copy Markdown
Member Author

The build failure here seems to be from an unrelated flaky test

@mrocklin
mrocklin merged commit 785d1dc into dask:master Apr 4, 2019
@mrocklin

mrocklin commented Apr 4, 2019

Copy link
Copy Markdown
Member

Thanks @jrbourbeau

My apologies for the intermittent failures.

@jrbourbeau
jrbourbeau deleted the use_ensure_dict branch April 4, 2019 04:38
muammar added a commit to muammar/distributed that referenced this pull request Apr 6, 2019
* upstream/master:
  Use ensure_dict instead of dict (dask#2594)
  Specify protocol in LocalCluster (dask#2489)
darindf pushed a commit to darindf/distributed that referenced this pull request Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants