Skip to content

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

Merged
leonsenft merged 1 commit into
angular:mainfrom
alxhub:sf/lazy-fields
Mar 20, 2026
Merged

perf(forms): lazily instantiate signal form fields#67344
leonsenft merged 1 commit into
angular:mainfrom
alxhub:sf/lazy-fields

Conversation

@alxhub

@alxhub alxhub commented Feb 26, 2026

Copy link
Copy Markdown
Member

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

@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
@alxhub alxhub added the target: major This PR is targeted for the next major release label Mar 17, 2026
@alxhub alxhub added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Mar 17, 2026
Comment thread packages/forms/signals/src/field/structure.ts Outdated
Comment thread packages/forms/signals/src/field/structure.ts Outdated
Comment thread packages/forms/signals/src/schema/logic_node.ts Outdated
Comment thread packages/forms/signals/test/node/api/structure.spec.ts
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
@alxhub alxhub added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Mar 20, 2026
@alxhub

alxhub commented Mar 20, 2026

Copy link
Copy Markdown
Member Author

Presubmit was "green"

@leonsenft leonsenft merged commit 98c5afd into angular:main Mar 20, 2026
21 of 23 checks passed
@leonsenft

Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Apr 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: forms area: performance Issues related to performance forms: signals merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Signal forms: poor performances with large arrays

3 participants