Skip to content

Perf compiler static objects#68720

Draft
GeorgySerga wants to merge 6 commits into
angular:mainfrom
GeorgySerga:perf-compiler-static-objects
Draft

Perf compiler static objects#68720
GeorgySerga wants to merge 6 commits into
angular:mainfrom
GeorgySerga:perf-compiler-static-objects

Conversation

@GeorgySerga
Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe: Performance optimization

What is the current behavior?

Issue Number: #56100

Previously, the compiler generated unique arrow function factory wrappers (() => ({...})) and ɵɵpureFunction0 calls 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?

  • Yes
  • No

Other information

Draft PR to execute E2E regression benchmarks across main vs. HEAD.

…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.
@angular-robot angular-robot Bot added area: performance Issues related to performance area: compiler Issues related to `ngc`, Angular's template compiler labels May 13, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 13, 2026
@GeorgySerga
Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler area: performance Issues related to performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant