perf: array comparison reference equality + numeric fast path#674
Merged
stephenamar-db merged 1 commit intodatabricks:masterfrom Apr 8, 2026
Merged
Conversation
Add reference equality check (xi eq yi) in the array comparison loop before type dispatch. When arrays share elements (e.g., long_array + [1] < long_array + [2] where long_array has 1M shared elements), this skips type dispatch for all identical references. Also inline numeric fast path (double compare without polymorphic compare() dispatch) for the common case where both elements are Num. Upstream: jit branch commits f7ad961, 62437d8
fa49ccf to
b9d479c
Compare
stephenamar-db
approved these changes
Apr 8, 2026
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 comparison in the evaluator compares element-by-element. Two optimizations are possible:
ValdispatchKey Design Decision
Add reference equality short-circuit and inline numeric comparison fast path in the array comparison loop.
Modification
Evaluator.scala: Added reference equality check for arrays, inline numeric fast path for element comparisonBenchmark Results
JMH (JVM, 3 iterations)
References
he-pin/sjsonnetjit branch array comparison optimizationResult
-8% to -18% JVM improvement for array comparison via reference equality short-circuit and numeric fast path.