perf: collect static apply args in one pass#838
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
perf: collect static apply args in one pass#838He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Conversation
Motivation: Reduce optimizer overhead when trying to fold statically-known function application arguments. Modification: Replace the forall-then-map sequence with one while loop that collects Val arguments and exits on the first non-static argument. Result: Static apply detection preserves behavior while avoiding duplicate traversal and casts.
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 repeated traversal in static function-application optimization.
Key Design Decision:
Keep the same folding condition: all arguments must already be
Val. The change only combines detection and collection into one pass.Modification:
StaticOptimizer.tryStaticApplynow fills anArray[Val]with a while loop and exits as soon as it sees a non-static argument, replacing the oldforallplusmap/asInstanceOfsequence.Benchmark Results:
OptimizerBenchmark.mainJMH0.422 +/- 0.004 ms/op0.414 +/- 0.005 ms/op-1.90%realistic2.jsonnet83.700 +/- 1.034 ms84.124 +/- 1.252 ms+0.51%Analysis:
The broader historical shortcut was tested and rejected as noisy/negative; this PR keeps only the stable one-pass collection piece. 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
0f1fba66.Result:
Local
./mill --no-server -j 1 __.reformatand./mill --no-server -j 1 __.testpassed on this split branch (2066/2066).