Skip to content

perf(forms): avoid spurious recomputation in FormField.parseErrors#68624

Open
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:perf/forms-parseErrors-shallow-equal
Open

perf(forms): avoid spurious recomputation in FormField.parseErrors#68624
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:perf/forms-parseErrors-shallow-equal

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

@arturovt arturovt commented May 7, 2026

parseErrors in FormField always produced a new array on every recomputation, even when nothing actually changed. The ?? [] fallback created a new empty array whenever parseErrorsSource was undefined, and .map() also returned new object references each time.

Since computed signals use reference equality by default, those new arrays were treated as changed values. That caused unnecessary updates to propagate through validationState.parseErrors and the combined errors chain, triggering extra recomputations during change detection.

Fix this by adding {equal: shallowArrayEquals} to the parseErrors computed, matching the existing errors computed and the validation computeds in field/validation.ts.

This prevents empty arrays from triggering updates while still correctly propagating real parse-error changes.


Note: both old value and new value are [].

image

@pullapprove pullapprove Bot requested a review from thePunderWoman May 7, 2026 19:14
@angular-robot angular-robot Bot added the area: performance Issues related to performance label May 7, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 7, 2026
@thePunderWoman thePunderWoman requested review from alxhub and leonsenft and removed request for thePunderWoman May 7, 2026 19:59
`parseErrors` in `FormField` always produced a new array on every recomputation, even when nothing actually changed. The `?? []` fallback created a new empty array whenever `parseErrorsSource` was undefined, and `.map()` also returned new object references each time.

Since computed signals use reference equality by default, those new arrays were treated as changed values. That caused unnecessary updates to propagate through `validationState.parseErrors` and the combined errors chain, triggering extra recomputations during change detection.

Fix this by adding `{equal: shallowArrayEquals}` to the `parseErrors` computed, matching the existing `errors` computed and the validation computeds in `field/validation.ts`.

This prevents empty arrays from triggering updates while still correctly propagating real parse-error changes.
@arturovt arturovt force-pushed the perf/forms-parseErrors-shallow-equal branch from efb68dd to 0f168cf Compare May 7, 2026 21:22
@arturovt arturovt changed the title perf(forms/signals): avoid spurious recomputation in FormField.parseErrors perf(forms): avoid spurious recomputation in FormField.parseErrors May 7, 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.

2 participants