Skip to content

Conversation

@wzx140
Copy link
Contributor

@wzx140 wzx140 commented Aug 27, 2024

What changes were proposed in this pull request?

In ProjectingInternalRow, accessing colOrdinals causes poor performace. Replace colOrdinals with the IndexedSeq type.

Why are the changes needed?

Replace colOrdinals with the IndexedSeq type.

Does this PR introduce any user-facing change?

No

How was this patch tested?

No need to add UT

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the SQL label Aug 27, 2024
@wzx140
Copy link
Contributor Author

wzx140 commented Aug 27, 2024

@aokolnychyi Could you please review it? Really thanks!


object ProjectingInternalRow {
def apply(schema: StructType, colOrdinals: Seq[Int]): ProjectingInternalRow = {
new ProjectingInternalRow(schema, colOrdinals.toIndexedSeq)
Copy link
Member

Choose a reason for hiding this comment

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

Do you have benchmark number? cc @yaooqinn

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a classic "accidentally quadratic" O(n^2) issue so you could achieve pretty arbitrary speedups with a contrived benchmark.

From the flamegraph attached to https://issues.apache.org/jira/browse/SPARK-49408 it seems like this would make a pretty substantial difference for that test query: it looks like ~94% of the time was being spent in list traversal.

@yaooqinn yaooqinn closed this in 37f2fa9 Sep 5, 2024
yaooqinn added a commit that referenced this pull request Sep 5, 2024
### What changes were proposed in this pull request?
In ProjectingInternalRow, accessing colOrdinals causes poor performace. Replace colOrdinals with the IndexedSeq type.

### Why are the changes needed?
Replace colOrdinals with the IndexedSeq type.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
No need to add UT

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #47890 from wzx140/project-row-fix.

Lead-authored-by: wzx <[email protected]>
Co-authored-by: Kent Yao <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
(cherry picked from commit 37f2fa9)
Signed-off-by: Kent Yao <[email protected]>
yaooqinn added a commit that referenced this pull request Sep 5, 2024
### What changes were proposed in this pull request?
In ProjectingInternalRow, accessing colOrdinals causes poor performace. Replace colOrdinals with the IndexedSeq type.

### Why are the changes needed?
Replace colOrdinals with the IndexedSeq type.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
No need to add UT

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #47890 from wzx140/project-row-fix.

Lead-authored-by: wzx <[email protected]>
Co-authored-by: Kent Yao <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
(cherry picked from commit 37f2fa9)
Signed-off-by: Kent Yao <[email protected]>
@yaooqinn
Copy link
Member

yaooqinn commented Sep 5, 2024

Merged to master/3.5/3.4.

Thank you all.

turboFei pushed a commit to turboFei/spark that referenced this pull request Nov 6, 2025
### What changes were proposed in this pull request?
In ProjectingInternalRow, accessing colOrdinals causes poor performace. Replace colOrdinals with the IndexedSeq type.

### Why are the changes needed?
Replace colOrdinals with the IndexedSeq type.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
No need to add UT

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#47890 from wzx140/project-row-fix.

Lead-authored-by: wzx <[email protected]>


(cherry picked from commit 37f2fa9)

Signed-off-by: Kent Yao <[email protected]>
Co-authored-by: wzx <[email protected]>
Co-authored-by: Kent Yao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants