Insertion speed of new dataset elements
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What is your issue?
In https://github.com/pydata/xarray/pull/7221 I showed that a major contributor the slowdown in inserting a new element was the cost associated with an internal only debugging assert statement.
The benchmarks results 7221 and 7222 are pretty useful to look at.
Thank you for encouraging the creation of a "benchmark" so that we can monitor the performance of element insertion.
Unfortunately, that was the only "free" lunch I got.
A few other minor improvements can be obtained with:
https://github.com/pydata/xarray/pull/7222
However, it seems to me that the fundamental reason this is "slow" is because element insertion is not so much "insertion" as it is:
- Dataset Merge
- Dataset Replacement of the internal methods.
This is really solidified in the https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L4918
In my benchmarks, I found that in the limit of large datasets, list comprehensions of 1000 elements or more were often used to "search" for variables that were "indexed" https://github.com/pydata/xarray/blob/ca57e5cd984e626487636628b1d34dca85cc2e7c/xarray/core/merge.py#L267
I think a few speedsups can be obtained by avoiding these kinds of "searches" and list comprehensions. However, I think that the dataset would have to provide this kind of information to the merge_core routine, instead of the merge_core routine recreating it all the time.
Ultimately, I think you trade off "memory footprint" (due to the potential increase of datastructures you keep around) of a dataset, and "speed".
Anyway, I just wanted to share where I got.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the insertion path in xarray/core/dataset.py around line 4918 and the indexed-variable search in xarray/core/merge.py around line 267. Compare the benchmark results from PRs 7221 and 7222, then identify a concrete optimization scope and performance criterion before changing dataset or merge behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100