-
-
Notifications
You must be signed in to change notification settings - Fork 18.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
Potential perf regressions introduced by Copy-on-Write #57431
Comments
Thanks for the list! reshape.Unstack.time_full_product
I am using pandas 2.2.0 to easily be able to switch between then default and CoW mode. With that, I can reproduce a slowdown in pandas/pandas/core/reshape/reshape.py Lines 242 to 244 in f538741
arithmetic.FrameWithFrameWide.time_op_different_blocks op=; shape=(1000000, 10)
This I can also reproduce, and a profile indicates the slowdown comes entirely from the actual
So something seems to go wrong in the DataFrame constructor. With CoW enabled, this should make a copy by default, but when making this copy, it seems to not use the correct C vs F order. series_methods.ToNumpy.time_to_numpy
gives
In this case there is some extra work being done to return a read-only view: Lines 667 to 669 in f538741
So it might be this is just that (but haven't checked in detail, from a quick profile nothing stood really out apart from just the body of |
Starting a list here what is a false-positive/expected: both to_dict cases are only as fast because of the item_cache which is something we removed, so nothing we can do
also item_cache, iterating over the columns once is actually twice as fast now, but doing it repeatedly scales linearly now, but this is expected
|
For the several |
For the various arithmetic.NumericInferOps.time_add - dtype=<class 'numpy.int16'> cases (also for |
For strings.Construction.time_construction, the reason of the slowdown is that |
dtype = "float"
axis = 0
values = np.random.randn(100000, 4)
df = pd.DataFrame(values).astype(dtype)
%timeit df.sum(axis=axis) This was also because of the constructor copying the array but not creating the correct columnar layout, and so this should be fixed on main with #57459 (confirmed locally, in a few days we should also see this on the ASV results) |
series_methods.Fillna.time_fillna - dtype='string' dtype = "string"
N = 10**6
data = np.array([str(i) * 5 for i in range(N)], dtype=object)
na_value = pd.NA
fill_value = data[0]
ser = pd.Series(data, dtype=dtype)
ser[::2] = na_value
%timeit ser.fillna(fill_value) This is a slowdown that I can reproduce, and is due to the additional pandas/pandas/core/internals/blocks.py Lines 2321 to 2329 in 3cc5afa
So for CoW, we added the additional check to see if there are actually NAs to fill, and if not just return the original values + the correct refs. Now, that is also only for our own object-dtype string dtype, so given we have pyarrow-backed strings as a faster alternative if you care about performance, this is probably an OK trade-off (since the |
Although after taking a quick look at |
I've looked through the most recent benchmarks, confirmed #57431 (comment), and checked off the box. |
PR #56633 may have induced a performance regression. If it was a necessary behavior change, this may have been expected and everything is okay.
Please check the links below. If any ASVs are parameterized, the combinations of parameters that a regression has been detected for appear as subbullets.
Subsequent benchmarks may have skipped some commits. The link below lists the commits that are between the two benchmark runs where the regression was identified.
Commit Range
cc @phofl
The text was updated successfully, but these errors were encountered: