perf(forms): lazily instantiate signal form fields#67344
Open
alxhub wants to merge 1 commit intoangular:mainfrom
Open
perf(forms): lazily instantiate signal form fields#67344alxhub wants to merge 1 commit intoangular:mainfrom
alxhub wants to merge 1 commit intoangular:mainfrom
Conversation
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
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.
Currently, Signal Forms eagerly instantiates all nodes in the form tree because
childrenMapiterates over thevalueand creates aFieldNodefor 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
childrenMaplazy by default, skipping materialization for children without schema logic. This is achieved by introducinghasLogicRules()andanyChildHasLogic()across theLogicNodehierarchy. Fields are now only instantiated when a direct read occurs viagetChild()(which calls the newensureChildrenMap()) or if their subtree requires eager evaluation due to existing validation rules.Fixes #67212