Repository navigation
Estimate dict sizes properly - #6154
Conversation
|
In terms of microbenchmarks of the new code, see the screenshot below. What we can observe is that the new function is consistently slower (even for the sample_dict_very_small) case which is something I haven't understood, yet. The dask-benchmarks for distributed stay the same within margin of error so I'll refrain from posting the results here. Not sure if the benchmarks include everything relevant |
|
This looks good to me. I suggest two small changes:
Thank you for doing this @fjetter |
Even if the dictionary is larger than ten elements? |
|
I was curious about this PR when applied to GPU objects and in both cases, In [3]: import cudf
In [5]: sr = cudf.Series([1, 2, 3])
In [6]: sample_dict = {k: sr for k in range(100)}
In [7]: %timeit sizeof_python_dict(sample_dict)
43.1 µs ± 226 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
In [8]: %timeit sizeof_python_dict_orig(sample_dict)
361 ns ± 0.826 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [10]: arr = cupy.arange(100)
In [11]: sample_dict = {c: arr for c in range(100)}
In [12]: %timeit sizeof_python_dict(sample_dict)
32.3 µs ± 122 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
In [13]: %timeit sizeof_python_dict_orig(sample_dict)
361 ns ± 3.55 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) |
@mrocklin Yes, the recursion order for a dict like sizeof_dict In particular, the sampling within The only change to previous functionality (other than dicts being more accurately estimated) is that now all python builtin collections are sampled instead of fully measured.
@quasiben The |
|
Removed the cytoolz import again since in the end we loop over ten elements where there is no speedup |
Right, but I think that a dict of numpy arrays or pandas dataframes would measure differently now. My understanding is that this is your primary motivation for this change. You wanted dicts of dataframes to be measured somewhat accurately. It would be good to put that desired behavior into a test so that it doesn't get accidentally reverted. |
|
I've added a small test |
Got it. Thanks! |


This would be the implementation alternative for #6149 which is supposed to address the issue that the size of intermediate shuffle tasks are not measured since they are usually dicts with > 10 keys.
This issue has been frequently discussed and there were some concerns about performance, most notably dask/distributed#1626
For the sampling I also tried to use
(cy)toolz.itertoolz.random_samplebut the builtin random performed the same so I chose to go this way.Regarding mirco benchmarks of the function this code is useful
Benchmarks from https://github.com/dask/dask-benchmarks will follow
xref #2456