Skip to content

perf(forms): lazily instantiate signal form fields#67344

Open
alxhub wants to merge 1 commit intoangular:mainfrom
alxhub:sf/lazy-fields
Open

perf(forms): lazily instantiate signal form fields#67344
alxhub wants to merge 1 commit intoangular:mainfrom
alxhub:sf/lazy-fields

Conversation

@alxhub
Copy link
Member

@alxhub alxhub commented Feb 26, 2026

Currently, Signal Forms eagerly instantiates all nodes in the form tree because childrenMap iterates over the value and creates a FieldNode for every property. This ensures validation side-effects are run early, but creates pure overhead for fields without validation logic unless explicitly accessed.

This commit makes childrenMap lazy by default, skipping materialization for children without schema logic. This is achieved by introducing hasLogicRules() and anyChildHasLogic() across the LogicNode hierarchy. Fields are now only instantiated when a direct read occurs via getChild() (which calls the new ensureChildrenMap()) or if their subtree requires eager evaluation due to existing validation rules.

Fixes #67212

Currently, Signal Forms eagerly instantiates all nodes in the form tree because `childrenMap` iterates over the `value` and creates a `FieldNode` for every property. This ensures validation side-effects are run early, but creates pure overhead for fields without validation logic unless explicitly accessed.

This commit makes `childrenMap` lazy by default, skipping materialization for children without schema logic. This is achieved by introducing `hasLogicRules()` and `anyChildHasLogic()` across the `LogicNode` hierarchy. Fields are now only instantiated when a direct read occurs via `getChild()` (which calls the new `ensureChildrenMap()`) or if their subtree requires eager evaluation due to existing validation rules.

Fixes angular#67212
@angular-robot angular-robot bot added area: performance Issues related to performance area: forms labels Feb 26, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: forms area: performance Issues related to performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signal forms: poor performances with large arrays

1 participant