perf: optimize comparison operators and addSuper allocation#691
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: optimize comparison operators and addSuper allocation#691He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
Refactor comparison and equality operations to avoid unnecessary allocations and improve dispatch efficiency. Changes: - Add rawDouble method to Val.Num for NaN-check-free access in comparison operations (consistent with existing pattern-match extraction behavior) - Refactor OP_<, OP_>, OP_<=, OP_>= to nested match to avoid Tuple2 allocation on every comparison - Refactor compare() to nested match with java.lang.Double.compare, Boolean.compare, and Integer.compare for cleaner dispatch - Use rawDouble in equal() for numeric comparison - Add addSuper fast path for chain-length-1 objects to avoid ArrayBuilder + Array allocation Upstream: jit branch commit b6f8b6d
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
Comparison operators (
<,>,<=,>=,==,!=) and object merging (+with super) are among the most frequently executed operations. Two sources of overhead:isInstanceOfchecks for each comparisonaddSuperallocation: Object merge creates intermediate collections even when unnecessaryKey Design Decision
addSuperallocation by reusing existing data structures where possibleModification
Evaluator.scala: Streamlined comparison operator dispatch, eliminated boxing in numeric comparisonsVal.scala: OptimizedaddSuperto reduce allocation for common patternsBenchmark Results
JMH (JVM, 3 iterations)
Analysis
References
he-pin/sjsonnetjit branch, comparison/addSuper optimization pathResult
-8% to -16% JVM improvement across all key benchmarks by streamlining comparison dispatch and reducing addSuper allocation.