Skip to content
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

perf(python): Optimize DataFrame.iter_rows for smaller buffer sizes #12804

Merged

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Nov 30, 2023

Realised we could move a check out of the inner buffer/offset loop; with the default buffer size I see negligible speedups (low single-digit percentage at best), but with smaller buffer sizes there can be a meaningful gain.

Example

(Worst case scenario; small buffer, few cols)

from codetiming import Timer
import polars as pl

df = pl.DataFrame({"x": range(500_000), "y": range(-500_000,0)})
with Timer():
    data = list(df.iter_rows(named=True, buffer_size=8))
BEFORE: 1.216 seconds
 AFTER: 0.894 seconds  (~35% faster)

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars labels Nov 30, 2023
@alexander-beedie alexander-beedie changed the title perf(python): optimise iter_rows, especially for smaller buffer sizes perf(python): optimise iter_rows for smaller buffer sizes Nov 30, 2023
@ritchie46 ritchie46 merged commit 08b1c95 into pola-rs:main Dec 1, 2023
24 checks passed
@alexander-beedie alexander-beedie deleted the minor-iter-rows-optimisation branch December 1, 2023 08:19
@stinodego stinodego changed the title perf(python): optimise iter_rows for smaller buffer sizes perf(python): Optimize DataFrame.iter_rows for smaller buffer sizes Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance issues or improvements python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants