perf: skip assert super-chain walk for assert-free objects#698
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: skip assert super-chain walk for assert-free objects#698He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
Add hasAnyAsserts flag to Val.Obj, computed O(1) at construction time from the super chain. When false, triggerAllAsserts returns immediately without walking the super chain or setting the asserting guard flag. The flag is a simple inductive definition: hasAnyAsserts = (triggerAsserts != null) || (super?.hasAnyAsserts) This is safe because: - Super chains are immutable, acyclic, and built bottom-up - triggerAsserts is private val (no post-construction mutation) - addSuper/removeKeys properly propagate via new object construction - No re-entrancy risk when skipping assert-free chains Benchmark: bench.02 47.534 → 44.826 ms/op (-5.7%) Upstream: jit branch commit 85ca07c
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
When accessing fields on a
Val.Obj, the evaluator walks the super-chain to trigger allassertstatements. For objects without any assertions (the common case), this walk is wasted work — iterating through potentially deep inheritance chains for no effect.Key Design Decision
Add a
hasAssertsflag toVal.Objthat tracks whether the object or any of its supers contain assertions. Skip the super-chain walk entirely whenhasAsserts == false.Modification
Val.scala: AddedhasAssertsflag, propagated through object merge (+)Evaluator.scala: Guard assert walk withhasAssertscheckBenchmark Results
JMH (JVM, 3 iterations)
Analysis
References
he-pin/sjsonnetjit branch commit85ca07caResult
-7% to -21% JVM improvement by skipping unnecessary assert super-chain walks for assertion-free objects.