Skip to content

perf: collect static apply args in one pass#838

Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:perf/static-apply-args-one-pass
Open

perf: collect static apply args in one pass#838
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:perf/static-apply-args-one-pass

Conversation

@He-Pin
Copy link
Copy Markdown
Contributor

@He-Pin He-Pin commented May 11, 2026

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.tryStaticApply now fills an Array[Val] with a while loop and exits as soon as it sees a non-static argument, replacing the old forall plus map/asInstanceOf sequence.

Benchmark Results:

Benchmark master/prior PR #838 Delta Notes
OptimizerBenchmark.main JMH 0.422 +/- 0.004 ms/op 0.414 +/- 0.005 ms/op -1.90% Targeted optimizer benchmark from exploration run.
Scala Native hyperfine realistic2.jsonnet 83.700 +/- 1.034 ms 84.124 +/- 1.252 ms +0.51% Output matched master; end-to-end CLI guard is neutral/noisy.

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 __.reformat and ./mill --no-server -j 1 __.test passed on this split branch (2066/2066).

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.
@He-Pin He-Pin marked this pull request as ready for review May 11, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant