perf: trim static scope map allocation#837
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
Conversation
Motivation: Reduce allocation overhead in the static expression transform scope setup without changing optimizer semantics. Modification: Build the immutable scope mapping with a direct while loop instead of zipWithIndex/map intermediate tuples and arrays. Result: Optimizer setup keeps the same immutable-scope behavior while doing less temporary allocation.
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:
Reduce optimizer allocation overhead in static scope construction without changing name-resolution semantics.
Key Design Decision:
Keep the existing immutable scope representation and only replace intermediate collection construction with a direct loop.
Modification:
ScopedExprTransformnow builds the child scope mapping with a while loop instead ofzipWithIndex.map, avoiding tuple and intermediate collection allocation.Benchmark Results:
OptimizerBenchmark.mainJMH0.432 +/- 0.004 ms/op0.422 +/- 0.004 ms/op-2.31%realistic2.jsonnet83.438 +/- 1.304 ms83.871 +/- 1.111 ms+0.52%Analysis:
This is intentionally smaller than the historical mutable-scope idea; it keeps the safer immutable invariant while trimming hot setup work. The Native CLI guard does not show a material end-to-end win, but the targeted optimizer benchmark is positive.
References:
Source exploration commit: He-Pin/sjsonnet
b1a42ad8.Result:
Local
./mill --no-server -j 1 __.reformatand./mill --no-server -j 1 __.testpassed on this split branch (2066/2066).