Skip to content

Avoid using Delayed in to_csv and to_parquet - #7968

Merged
jrbourbeau merged 7 commits into
dask:mainfrom
mrocklin:compute-without-gather
Aug 4, 2021
Merged

jrbourbeau merged 7 commits into
dask:mainfrom
mrocklin:compute-without-gather

Conversation

@mrocklin

@mrocklin mrocklin commented Jul 30, 2021 •

Copy link
Copy Markdown
Member

This accomplishes two things:

  1. Lets dataframe optimizations through
  2. Avoids a final synchronization point in the graph
    which improves scheduling heuristics

Edit

I first used dask.compute more liberally in if compute: branches in order to avoid the final delayed call. Then I remembered the handy compute_as_if_collection function which lets us avoid creating anything, and directly specify the collection type. This is the second commit and probably the right way forward.

This accomplishes two things:

1.  Lets dataframe optimizations through
2.  Avoids a final synchronization point in the graph
    which improves scheduling heuristics
@github-actions github-actions Bot added the array label Jul 30, 2021
Comment thread dask/dataframe/io/parquet/core.py Outdated
if compute:
import dask

dask.compute(*part_tasks, **{compute_kwargs or {}})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think part_tasks is still just a list of keys. dsk is where the actual tasks are

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'm iterating on this. Stay tuned!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, see recent commit I think

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the edit in the top comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mrocklin

Copy link
Copy Markdown
Member Author

OK, so I'm doing something dumb with parquet, but after staring at it for 20m I'm hoping that @rjzamora can help me out.

I do generally think that this is a good direction to go in though. It's also probably something that we should watch out for.

@rjzamora

Copy link
Copy Markdown
Member

Then I remembered the handy compute_as_if_collection function which lets us avoid creating anything, and directly specify the collection type.

Interesting! I was actually unaware of compute_as_if_collection

@mrocklin

Copy link
Copy Markdown
Member Author

Interesting! I was actually unaware of compute_as_if_collection

Yeah, I had totally forgotten about it. Probably it was my job to tell you about it in the first place :)

@jrbourbeau

Copy link
Copy Markdown
Member

I noticed is compute_as_if_collection we're converting to a low-level task graph

dsk2 = optimization_function(cls)(ensure_dict(dsk), keys, **kwargs)

Maybe we should leave that to the optimization function instead?

@mrocklin

Copy link
Copy Markdown
Member Author

Maybe we should leave that to the optimization function instead?

Probably a good idea! This function is old.

@jrbourbeau

Copy link
Copy Markdown
Member

xref #7969 -- let's see if tests pass : )

@jrbourbeau jrbourbeau changed the title Avoid using Delayed in to_csv and to_parquet [WIP] Avoid using Delayed in to_csv and to_parquet Aug 4, 2021
Comment thread dask/dataframe/io/parquet/core.py Outdated
Comment on lines +867 to +869
return compute_as_if_collection(DataFrame, graph, name, **compute_kwargs)
else:
return Delayed(name, graph)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mrocklin, overall this looks good. I'm wondering if this change is necessary. I don't think there are any Dask DataFrames involved with create_metadata_file, so I could think that the normal Delayed optimizations (i.e. culling) would be the best we could do. Am I missing something?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that could be. I went through this file quickly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. I'm going to revert this one change as I'm pretty sure create_metadata_file won't benefit from using DataFrame optimizations (@rjzamora should feel free to correct me on that). Everything else looks good, so I'll merge this in after CI finishes

@jrbourbeau jrbourbeau changed the title [WIP] Avoid using Delayed in to_csv and to_parquet Avoid using Delayed in to_csv and to_parquet Aug 4, 2021
@jrbourbeau
jrbourbeau merged commit 8d6f2da into dask:main Aug 4, 2021
@mrocklin
mrocklin deleted the compute-without-gather branch August 6, 2021 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants