Skip to content

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.

@github-actions
Copy link

We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!

@github-actions github-actions bot added the Stale label Apr 20, 2025
@github-actions github-actions bot closed this Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants