Perf compiler static objects#68720
Draft
GeorgySerga wants to merge 6 commits into
Draft
Conversation
…ion0
Optimize the code generation for static object and array literals in templates. Previously, even if an object literal was completely static (e.g., `{name: 'Angular'}`), the compiler generated an arrow function wrapper and a `ɵɵpureFunction0` call to cache it.
Now, for literals with zero arguments (completely static), the compiler generates a direct reference to a constant object in the constant pool, and skips the `ɵɵpureFunction0` call and the corresponding slot allocation in the view.
This reduces generated code size, saves memory by not using slots in `LView`, and avoids the runtime overhead of calling `ɵɵpureFunction0` on every render.
Fixes angular#56100
… caching
Optimize the code generation and runtime reification for flat static object and
array literals in templates. Previously, all static literals generated unique arrow
function factory wrappers and `ɵɵpureFunction0` calls, which bloated JavaScript
bundles and incurred unnecessary function evaluation overhead during bootstrapping.
For flat static object and array literals (literals with zero dynamic arguments and
no nested objects or arrays), the compiler now generates a direct reference to a
static constant pool object and reifies the call using specialized 1-slot cloner
instructions (`ɵɵcloneObject` / `ɵɵcloneArray`).
These instructions perform a highly optimized V8 shape memory clone (`{...const}`) on
the first render and instantly return the cached reference from `LView` on all
subsequent change detection passes. Deeply nested literals automatically fall back
to unique factory wrapper generation to guarantee 100% reference sandboxing across
component instances.
This architectural change achieves:
- ~18.8% faster component instantiation during first render
- 10 characters saved per flat static literal in minified bundles
- Zero growth in LView caching array heap memory footprint
- 100% backward compatibility and strict reference isolation
Fixes angular#56100
Ensure non-flat 0-argument pure functions are correctly wrapped in arrow functions so they can be evaluated by ɵɵpureFunction0 without throwing runtime errors. Also establishes a permanent E2E benchmark module under /modules/benchmarks.
Contributor
Author
|
/benchmark-compare main //modules/benchmarks/src/static_literals/ng2:perf_chromium |
…e goldens Ensure non-flat 0-argument pure functions are correctly wrapped in arrow functions during constant pool extraction so they can be evaluated at runtime by `ɵɵpureFunction0` without throwing type errors. Also updates remaining compliance test golden files (`linked`, `codegen`, and `full` modes) to expect specialized 1-slot cloner instructions (`ɵɵcloneObject` / `ɵɵcloneArray`) for flat static literals, and removes unused duplicate test files introduced in the initial branch commit.
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #56100
Previously, the compiler generated unique arrow function factory wrappers (
() => ({...})) andɵɵpureFunction0calls for all static object and array literals in templates, bloating JavaScript bundles and incurring unnecessary function evaluation overhead during bootstrapping.What is the new behavior?
For flat static object and array literals (literals with zero dynamic arguments and no nested objects or arrays), the compiler now emits a direct reference to a static constant pool object and reifies the call using specialized 1-slot cloner instructions (
ɵɵcloneObject/ɵɵcloneArray). Deeply nested literals safely fall back to unique factory wrappers to guarantee 100% reference sandboxing across component instances.Does this PR introduce a breaking change?
Other information
Draft PR to execute E2E regression benchmarks across
mainvs.HEAD.