-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Minimize concat memory usage #10866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimize concat memory usage #10866
Conversation
Closes pydata#10864 ``` | Change | Before [b5e4b0e] <main> | After [c9432cfc] <min-concat-mem> | Ratio | Benchmark (Parameter) | |----------|----------------------------|-------------------------------------|---------|---------------------------------| | - | 4.82G | 920M | 0.19 | combine.Concat1d.peakmem_concat | | - | 574±20ms | 54.0±0.6ms | 0.09 | combine.Concat1d.time_concat | ```
|
with reduced sizes for CI: |
This reverts commit f1dab89.
kmuehlbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcherian This is already very far away from my initial mediocre solution. Thanks, this will have extreme impact on our workflows. 🥇
xarray/structure/concat.py
Outdated
| file_start_indexes = np.append(0, np.cumsum(concat_dim_lengths)) | ||
| concat_index = np.arange(file_start_indexes[-1]) | ||
| concat_index_size = concat_index.size | ||
| concat_index_size = np.sum(concat_dim_lengths) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might squeeze a bit more, if we combine the calculation of the sum with the above np.cumsum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might even think about adding the np.cumsum - trick you did further below and pre-allocate file_start_indexes. Not sure how much that gives, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file_start_indexes is only ever allocated once, so doesn't seem worth it. We can use np.cumulative_sum(concat_dim_lengths, include_initial=True) once we require numpy>=2 I believe
* main: Update docs to reflect open_mfdataset default chunk behaviour (pydata#10567)
Kai, your solution solved a ~10year old bug IIRC! I should've spotted this at review. I think I assumed it scaled with number of files, ~O(10_000), instead of dimension size O(10_000_000). |
At least, someone complained about it now 😀 |
|
Thanks again @dcherian! Concatenators and combiners will have some spare time for doing more science now. 🎉 |
OK we were incredibly wasteful earlier!
cc @mjwillson
Would be good to add a benchmark for the reindexing case at some point
whats-new.rst