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: Don't rechunk in align_ if arrays are aligned #16850

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions crates/polars-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,18 @@ where
)
};
match (left.chunks.len(), right.chunks.len()) {
// All chunks are equal length
(1, 1) => (Cow::Borrowed(left), Cow::Borrowed(right)),
// All chunks are equal length
(a, b)
if a == b
&& left
.chunk_lengths()
.zip(right.chunk_lengths())
.all(|(l, r)| l == r) =>
{
(Cow::Borrowed(left), Cow::Borrowed(right))
},
(_, 1) => {
assert();
(
Expand Down Expand Up @@ -902,6 +913,16 @@ where
Cow::Owned(c.match_chunks(a.chunk_lengths())),
)
},
(len_a, len_b, len_c)
if len_a == len_b
&& len_b == len_c
&& a.chunk_lengths()
.zip(b.chunk_lengths())
.zip(c.chunk_lengths())
.all(|((a, b), c)| a == b && b == c) =>
{
(Cow::Borrowed(a), Cow::Borrowed(b), Cow::Borrowed(c))
},
_ => {
// could optimize to choose to rechunk a primitive and not a string or list type
let a = a.rechunk();
Expand Down