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

[SPARK-48568][SQL] Improve Performance of CodeFormatter #49261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anton-erofeev
Copy link

What changes were proposed in this pull request?

Replace scala StringBuilder with java StringBuilder

Why are the changes needed?

https://issues.apache.org/jira/browse/SPARK-48568

Does this PR introduce any user-facing change?

No

How was this patch tested?

Pass github actions

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

No

@github-actions github-actions bot added the SQL label Dec 21, 2024
@HyukjinKwon
Copy link
Member

Can we have a micro benchmark?

@LuciferYang
Copy link
Contributor

Can we have a micro benchmark?

+1 for micro benchmark. StringBuilder wraps j.l.StringBuilder,

final class StringBuilder(val underlying: java.lang.StringBuilder) extends AbstractSeq[Char]
  with ReusableBuilder[Char, String]
  with IndexedSeq[Char]
  with IndexedSeqOps[Char, IndexedSeq, StringBuilder]
  with IterableFactoryDefaults[Char, IndexedSeq]
  with java.lang.CharSequence
  with Serializable 

the functions should all directly operate on the underlying, so I'm not sure if this really brings a performance improvement. If it does, is this the only place worth change?

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

Happy New Year, @anton-erofeev . As the previous reviewers mentioned, this PR needs a proof of your claim in terms of the performance in the community.

Copy link
Contributor

@JoshRosen JoshRosen left a comment

Choose a reason for hiding this comment

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

The original JIRA description at https://issues.apache.org/jira/browse/SPARK-48568 by @ahirreddy mentions some performance results with a similar change during profiling of certain large test suites:

  • The reason for this change is that it substantially improves the performance of the CodeFormatter.
  • From some basic profiling, in a ~100s suite, code formatting took ~2.7 seconds of CPU time. Post change it takes about 800ms.
  • My hypothesis is that Java StringBuilder is much more JIT friendly. Scala's StringBuilder has many layers as it implements a significant portion of the Scala mutable collection API. It's also likely the case that the JVM has special JIT handling for Java StringBuilder

I vaguely recall having run into Java vs. Scala StringBuilder performance differences in some other context, but can't remember the details.

OTOH, I've also seen this to be a bit of a wash in less-scientific microbenchmarks of raw string appender performance.

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.

5 participants