-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Remove debugging slow assert statement #7221
Conversation
Gosh, that's quite dramatic! Impressive find @hmaarrfk. (out of interest, how did you find this?) I can see how that's quadratic when looping like that. I wonder whether using Would be interesting to see whether this was covered by our existing asv benchmarks. Would be a good benchmark to add if we don't have one already. |
Spyder profiler |
for more information, see https://pre-commit.ci
I wasn't able to find something that really benchmarked "large" datasets.
Added one. |
:/ not fun, the benchmark is failing. not sure why. |
I'm somewhat ocnfused, I can run the benchmark locally
|
Maybe 1000 loops is too much. Start with 100 maybe? We still want these benchmarks to be decently fast in the CI. |
I like large datasets as well. I seem to remember getting caught in similar places when creating my datasets. I think I solved it by using Variable instead, does doing something like this improve the performance for you? import xarray as xr
dataset = xr.Dataset()
dataset['a'] = xr.Variable(dims="time", data=[1])
dataset['b'] = xr.Variable(dims="time", data=[2]) |
Now the asv finishes at least! Could you make a separate PR for the asv? I don't think it runs it when comparing to the main branch. |
Ok. I'll want to rethink them. I know it looks quadratic time, but i really would like to test n=1000 and i have an idea |
for more information, see https://pre-commit.ci
I know it is not comparable, but I was really curious what "dictionary insertion" costs, in order to be able to understand if my comparisons were fair: codefrom tqdm import tqdm
import xarray as xr
from time import perf_counter
import numpy as np
N = 1000
# Everybody is lazy loading now, so lets force modules to get instantiated
dummy_dataset = xr.Dataset()
dummy_dataset['a'] = 1
dummy_dataset['b'] = 1
del dummy_dataset
time_elapsed = np.zeros(N)
# dataset = xr.Dataset()
dataset = {}
for i in tqdm(range(N)):
# for i in range(N):
time_start = perf_counter()
dataset[f"var{i}"] = i
time_end = perf_counter()
time_elapsed[i] = time_end - time_start
# %%
from matplotlib import pyplot as plt
plt.plot(np.arange(N), time_elapsed * 1E6, label='Time to add one variable')
plt.xlabel("Number of existing variables")
plt.ylabel("Time to add a variables (us)")
plt.ylim([0, 10])
plt.title("Dictionary insertion")
plt.grid(True) I think xarray gives me 3 order of magnitude of "thinking" benefit, so I'll take it!
|
Nice improvements. :) I haven't fully understood why we had that code though? |
I no longer remember why I added these checks, but I certainly did not expect to see this sort of performance penalty! |
We've been trying to understand why our code is slow. One part is that we use xarray.Datasets almost like dictionaries for our data. The following code is quite common for us
However, through benchmarks, it became obvious that the

merge_core
method of xarray was causing alot of slowdowns.main
branch:With this merge request:

whats-new.rst
api.rst