Optimize compiler, add controls for speed-size tradeoffs, and allow for AST as input - #4336
Open
DavidANeil wants to merge 44 commits into
Open
Optimize compiler, add controls for speed-size tradeoffs, and allow for AST as input#4336DavidANeil wants to merge 44 commits into
DavidANeil wants to merge 44 commits into
Conversation
Raise the default AST size-change threshold from 0.05% to 0.1% after two consecutive optimization-loop batches, while exposing a hidden flag and CompilerOptions setter to restore or tune the previous behavior. Controlled warm-worker Universal Canvas comparison: compiler time 168.181s -> 157.810s (6.17% faster), total action time 173.30s -> 163.01s (5.94% faster), pass runs 194 -> 186. Output grew 301 raw bytes out of 64,785,624 (0.000465%) and 212 gzip bytes out of 16,229,873 (0.001306%); JS and renaming-map hashes change because the loop stops earlier.
Add --output_remove_unused_code_report to write the compiler existing pass-indexed RemoveUnusedCode removal logs to a dedicated directory. Filter out unremovable and unrelated debug logs so diagnostics stay focused and never flood tracer stdout. CommandLineRunnerTest passes. Lucid Auth validation produced 11 report files containing 36,350 variable, property, polyfill, and argument removal records.
Add a hidden --optimization_loop_max_iterations flag for build systems that prefer a bounded compile-time/output-size tradeoff. Zero preserves Closure default adaptive behavior. CommandLineRunnerTest and PhaseOptimizerTest pass. The Lucid policy using this capability is benchmarked and committed separately.
Add a separate optimization-motion-loop cap so build systems can bound cross-chunk fixed-point work independently from code-removal loops. Preserve the existing infinite-loop error for uncapped motion loops. PhaseOptimizerTest and CommandLineRunnerTest pass. Lucid benchmark and policy are committed separately.
Universal Canvas: coalesceVariableNames fell from 3.245s wall / 4.143s CPU to 1.110s wall / 3.715s CPU, a 65.8% pass wall-time reduction. All 884 JavaScript outputs, 884 source maps, and both renaming maps are byte-identical.
Universal Canvas: flowSensitiveInlineVariables fell from 1.969s wall / 3.174s CPU to 0.479s wall / 4.146s CPU, a 75.7% pass wall-time reduction. All 884 JavaScript outputs, 884 source maps, and both renaming maps are byte-identical.
Universal Canvas: deadAssignmentsElimination fell from 795ms wall / 4.172s CPU to 201ms wall / 3.802s CPU, a 74.7% pass wall-time reduction. All 884 JavaScript outputs, 884 source maps, and both renaming maps are byte-identical.
Let worker threads collect changed and deleted scopes without mutating the shared timeline or notifying serial pass handlers. The compiler thread applies each buffer later in deterministic caller-selected order.
Use isolated optimization instances per worker and merge buffered scope changes in script order before retaining the existing serial changed-scope fixed point. Universal Canvas saves about 1.20s across early, normal, and late peephole passes. All 884 JavaScript outputs, 884 source maps, and both renaming maps are byte-identical.
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.
This PR is a collection of LLM-driven optimizations to the compiler.
It does include a few changes to the tracer mode, which were used for making these improvements, but if you would like I can revert those changes and only leave the actual optimizations.
For our closure-compiler pipeline we were able to get it down from 290s to 100s for a byte-equivalent version, and even faster when using the exposed speed-size tuning knobs. Not all of those speed improvements are local to the changes here, as those timings also include improvements to, for example, how we compress the assets after compilation completes.