perf(compiler-cli): use null instead of {} in ngDevMode spread fallback#68828
Open
arturovt wants to merge 1 commit into
Open
perf(compiler-cli): use null instead of {} in ngDevMode spread fallback#68828arturovt wants to merge 1 commit into
arturovt wants to merge 1 commit into
Conversation
The implicit signal debug name transform emits a conditional spread in
the prod branch of each ngDevMode ternary:
{ ...(ngDevMode ? { debugName: "x" } : {}) }
The falsy branch was `{}`, which allocates a short-lived object in V8's
young generation on every class instantiation. In large apps with many
signal-based properties this raises the minor GC (scavenger) frequency
on the startup critical path. TurboFan's escape analysis could eliminate
the allocation in theory, but proving escape requires inlining the
callee — not guaranteed at thousands of distinct call sites.
Change the fallback to `null`. ECMA-262 §13.2.5 defines `{...null}` as
a no-op, identical in behavior to `{...{}}`. V8 hits a fast nullish
check in the object-spread runtime and returns immediately with no heap
allocation.
Only the object-spread path is affected. The array-spread fallback
(`...(ngDevMode ? [...] : [])`) is unchanged — `[...null]` would throw.
6c3f2d4 to
91a3274
Compare
Member
|
This should end up being optimized out entirely, so this change wouldn't actually help perf |
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.
The implicit signal debug name transform emits a conditional spread in the prod branch of each ngDevMode ternary:
The falsy branch was
{}, which allocates a short-lived object in V8's young generation on every class instantiation. In large apps with many signal-based properties this raises the minor GC (scavenger) frequency on the startup critical path. TurboFan's escape analysis could eliminate the allocation in theory, but proving escape requires inlining the callee — not guaranteed at thousands of distinct call sites.Change the fallback to
null. ECMA-262 §13.2.5 defines{...null}as a no-op, identical in behavior to{...{}}. V8 hits a fast nullish check in the object-spread runtime and returns immediately with no heap allocation.Only the object-spread path is affected. The array-spread fallback (
...(ngDevMode ? [...] : [])) is unchanged —[...null]would throw.