perf: appendString bulk array copy via String.getChars#681
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: appendString bulk array copy via String.getChars#681He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
Collaborator
|
CI check found a scalafmt formatting violation in |
stephenamar-db
approved these changes
Apr 8, 2026
0a187be to
8834d96
Compare
Replace char-by-char appendUnsafeC loop with String.getChars bulk copy directly into CharBuilder's backing array. This eliminates per-character method call overhead and allows the JVM/native runtime to use optimized memory copy intrinsics. Upstream: 5e9686cd (appendString portion)
8834d96 to
5655ff2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The renderer's
appendStringmethod copies string characters one-by-one in a loop. For large strings (common in JSON rendering), this is slower than bulk array copy.Key Design Decision
Replace the character-by-character copy loop with
String.getChars()which uses optimizedSystem.arraycopy()internally for bulk memory transfer.Modification
appendStringfrom per-char loop toString.getChars()bulk copy (6 lines changed)Benchmark Results
JMH (JVM, 3 iterations)
Analysis
String.getChars()usesSystem.arraycopy()internally — SIMD-optimized on modern JVMsReferences
he-pin/sjsonnetjit branch commit5e9686cdResult
-9% to -18% JVM improvement by replacing per-char string copy with bulk array copy.