perf: optimize std.range allocation and add staticNull singleton#669
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: optimize std.range allocation and add staticNull singleton#669He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
Three targeted optimizations: 1. std.range: Replace Scala Range.map.toArray with direct while-loop array allocation. Avoids boxing through Range and .map intermediates. 2. Val.staticNull: Add singleton null value for runtime results where position information is not meaningful (e.g., if-then without else). Mirrors the existing staticTrue/staticFalse pattern. 3. visitIfElse: Use Val.staticNull instead of allocating new Val.Null instances for the implicit else branch. Upstream: jit branch commit c4ee6be Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
std.rangeallocates anArray[Eval]filled withVal.Nullplaceholders that are immediately overwritten. TheVal.Nullobject is also re-allocated for each null literal encountered.Key Design Decision
staticNullsingleton to avoid re-allocatingVal.Nullobjectsstd.rangearray initializationModification
Val.scala: AddedVal.staticNullsingletonArrayModule.scala: Optimized range allocation to use pre-sized arrayBenchmark Results
JMH (JVM, 3 iterations)
References
he-pin/sjsonnetjit branch range/null optimizationResult
-10% to -18% JVM improvement by reducing allocation in range creation and null literals.