Skip to content

PERF: avoid copy in concatenate_array_managers if reindex already copies #44559

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

Merged

Conversation

jorisvandenbossche
Copy link
Member

@jbrockmendel #42797 added an unconditional copy, while if you reindex the arrays, you already are sure you have a copy.

This gives a 20% improvement on some of the merge benchmarks.

@jorisvandenbossche jorisvandenbossche added ArrayManager Performance Memory or execution speed performance labels Nov 21, 2021
@jorisvandenbossche jorisvandenbossche added this to the 1.4 milestone Nov 21, 2021
@@ -94,7 +99,7 @@ def _concatenate_array_managers(
# concatting along the columns -> combine reindexed arrays in a single manager
assert concat_axis == 0
arrays = list(itertools.chain.from_iterable([mgr.arrays for mgr in mgrs]))
if copy:
if copy and axis1_needs_copy_this:
Copy link
Member

Choose a reason for hiding this comment

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

might be cleaner (and avoid copies in corner cases) to do this up in the for loop right before mgrs.append(mgr)

Copy link
Member Author

@jorisvandenbossche jorisvandenbossche Dec 3, 2021

Choose a reason for hiding this comment

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

Thanks, good idea, and that also simplified it quite a bit

@jreback
Copy link
Contributor

jreback commented Nov 28, 2021

lgtm @jbrockmendel comment could be addressed here

@@ -77,10 +77,16 @@ def _concatenate_array_managers(
# reindex all arrays
mgrs = []
for mgr, indexers in mgrs_indexers:
axis1_needs_copy = True
Copy link
Member

Choose a reason for hiding this comment

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

nitpick again: elsewhere in this file we do basically the same thing with made_copy = False

@jreback jreback merged commit 4b71090 into pandas-dev:master Dec 6, 2021
@jorisvandenbossche jorisvandenbossche deleted the am-perf-concat-mgrs-avoid-copy branch December 6, 2021 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants