Skip to content

Commit

Permalink
refactor(core): detect signal inputs at runtime using input flags (an…
Browse files Browse the repository at this point in the history
…gular#53571)

This commit introduces a new enum for capturing additional metadata
about inputs. Called `InputFlags`. These will be built up at compile
time and then propagated into the runtime logic, in a way that does
not require additional lookup dictionaries data structures, or
additional memory allocations for "common inputs" that do not have any flags.

The flags will incorporate information on whether an input is signal
based. This can then be used to avoid megamorphic accesses when such
input is set- as we'd not need to check the input field value. This also
avoids cases where an input signal may be used as initial value for an
input (as we'd not incorrectly detect the input as a signal input then).

The new metadata emit will be useful for incorporating additional
metadata for inputs, such as whether they are required etc (although
required inputs are a build-time only construct right now- but this is a
good illustration of why input flags can be useful). An alternative
could have been to have an additional boolean entry for signal inputs,
but allocating a number with more flexible input flags seems more future
proof and more reasonable andreadable.

More information on the megamorphic access when updating an input
signal
https://docs.google.com/document/d/1FpnFruviKb6BFTQfMAP2AMEqEB0FI7z-3mT_qm7lzX8/edit.

PR Close angular#53571
  • Loading branch information
devversion authored and amilamen committed Jan 26, 2024
1 parent cb14bb2 commit 32c55b9
Show file tree
Hide file tree
Showing 33 changed files with 724 additions and 393 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LifecycleComp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: LifecycleComp,
selectors: [["lifecycle-comp"]],
inputs: {nameMin: ["name", "nameMin"]},
inputs: {nameMin: [0, "name", "nameMin"]},
features: [$r3$.ɵɵNgOnChangesFeature],
decls: 0,
vars: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MyComponent.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
inputs:{
componentInput: "componentInput",
originalComponentInput: ["renamedComponentInput", "originalComponentInput"]
originalComponentInput: [0, "renamedComponentInput", "originalComponentInput"]
},
outputs: {
componentOutput: "componentOutput",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MyDirective.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs:{
directiveInput: "directiveInput",
originalDirectiveInput: ["renamedDirectiveInput", "originalDirectiveInput"]
originalDirectiveInput: [0, "renamedDirectiveInput", "originalDirectiveInput"]
},
outputs: {
directiveOutput: "directiveOutput",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
MyDirective.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs: {
functionDeclarationInput: ["functionDeclarationInput", "functionDeclarationInput", toNumber],
inlineFunctionInput: ["inlineFunctionInput", "inlineFunctionInput", (value, _) => value ? 1 : 0]
functionDeclarationInput: [2, "functionDeclarationInput", "functionDeclarationInput", toNumber],
inlineFunctionInput: [2, "inlineFunctionInput", "inlineFunctionInput", (value, _) => value ? 1 : 0]
},
features: [$r3$.ɵɵInputTransformsFeature]
});

0 comments on commit 32c55b9

Please sign in to comment.