perf: cached renderDouble for small integers + Builtin1/3 apply overrides#763
Draft
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Draft
perf: cached renderDouble for small integers + Builtin1/3 apply overrides#763He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
12b870c to
4c8c5ab
Compare
4c8c5ab to
93acd93
Compare
…ides Three optimizations: 1. RenderUtils.renderDouble: pre-cached string representations for integers 0-255, avoiding Long.toString allocation on every call. 2. Materializer.stringify: unified with renderDouble (removes duplicate integer fast-path code). 3. Builtin1.apply1 / Builtin3.apply3: added direct override methods that call evalRhs without creating intermediate Array. Upstream: jit branch commit 9917a68
93acd93 to
3ae5a56
Compare
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
RenderUtils.renderDoubleis called on every number materialization. Small integer values (0-255) are common in Jsonnet workloads (array indices, ASCII codepoints, counters), so caching their string representations avoids repeatedLong.toStringallocation.Builtin1andBuiltin3were also missing directapply1/apply3overrides whileBuiltin2already hadapply2, leaving avoidable intermediateArrayallocation on those builtin calls.Key Design Decision
RenderUtils.renderDoublefromMaterializer.stringifyso number rendering has one fast path.apply1andapply3overrides forBuiltin1andBuiltin3, matching the existingBuiltin2.apply2pattern.Modification
Renderer.scala: add a small integer string cache and use it when rendering non-negative integral doubles in range 0-255.Materializer.scala: delegate numeric stringification toRenderUtils.renderDoubleinstead of duplicating integer handling.Val.scala: addapply1override toBuiltin1andapply3override toBuiltin3.Benchmark Results
No benchmark was remeasured in this rebase/test cycle. Targeted benchmark work is deferred to the later serial benchmark batch.
Prior directional evidence from this PR:
Prior wider JMH sweep summary: 7 improvements, 8 regressions, 20 neutral on Apple Silicon single-shot average. Treat as directional only.
Analysis
The integer cache removes allocation for the hot 0-255 rendering range while preserving the existing rendering semantics for other numbers. The builtin apply overrides remove avoidable argument-array allocation and follow an existing code pattern. The current cycle was limited to safe rebase, formatting, full test validation, PR body normalization, and protected branch update.
References
9917a682fd1b3b1eResult
Rebase completed cleanly onto upstream/master. Validation in this cycle:
rtk ./mill __.reformat: SUCCESS; worktree remained clean.rtk ./mill __.test: SUCCESS.