perf: fast-path Num stringify in OP_+ string concatenation#684
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: fast-path Num stringify in OP_+ string concatenation#684He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
Add direct RenderUtils.renderDouble() call for Num+Str and Str+Num cases in binary OP_+ to avoid Materializer.stringify() dispatch overhead. stringify() performs a full pattern match on Val type just to extract the double for rendering. The direct call skips this dispatch entirely, which is significant for string template operations that concatenate many numbers with strings. Uses n.asDouble (not raw destructured double) to preserve the NaN guard that exists in Val.Num.asDouble — this ensures consistency with Materializer.stringify() error behavior for not-a-number values. Upstream: jit branch commit 4b1cd03
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 concatenating strings with
+, if one operand is a number, it must be converted to string. The current path goes throughMaterializer.stringifywhich has overhead from format dispatching and intermediate string creation.Key Design Decision
Add a fast path in
OP_+that detectsVal.Numoperands and converts them directly using the existingrenderDoubleutility, bypassing the fullMaterializer.stringifychain.Modification
Evaluator.scala: Added 2-line fast path check inOP_+string concatenation forVal.NumoperandsBenchmark Results
JMH (JVM, 3 iterations)
Analysis
References
he-pin/sjsonnetjit branch commit4b1cd032Result
Massive ROI optimization: 2 lines of code for -10% to -19% JVM improvement on number-to-string concatenation paths.