perf: Val.Arr arraycopy concat and while-loop asStrictArray#696
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: Val.Arr arraycopy concat and while-loop asStrictArray#696He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
Replace Scala ArrayOps '++' in Val.Arr.concat with direct System.arraycopy, avoiding ClassTag resolution and ArrayBuilder overhead. Replace arr.map(_.value) in asStrictArray with an explicit while-loop to avoid closure allocation. Redirect OP_+ array path to use the optimized concat method instead of asLazyArray ++ rArr.asLazyArray. Upstream: jit branch commit ffc34c2
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
Array concatenation (
+on arrays) andasStrictArraycurrently use functional/iterator patterns that allocate intermediate collections unnecessarily.Key Design Decision
Use
System.arraycopyfor array concatenation (zero-copy bulk memory transfer) and convertasStrictArrayfrom functional iteration to a while-loop to avoid closure and iterator allocation.Modification
System.arraycopy-based implementationasStrictArrayto while-loop iterationBenchmark Results
JMH (JVM, 3 iterations warmup + 3 measurement)
Analysis
The comparison2 improvement (-19.6%) reflects the heavy array usage in that benchmark.
System.arraycopyis a JVM intrinsic that compiles to nativememcpy— always faster than element-by-element copy through iterators. The while-loop conversion eliminates closure allocation in tight loops.References
Result
All 23 tests pass. All benchmarks positive, no regressions.