Performance: Custom validators
MEDIUM IMPACT
Custom validators affect form validation responsiveness and user interaction speed.
function fastValidator(control: AbstractControl): ValidationErrors | null { // Simple synchronous check return control.value && control.value.length > 3 ? null : { 'tooShort': true }; }
function slowValidator(control: AbstractControl): ValidationErrors | null { // Heavy synchronous computation or API call simulation for (let i = 0; i < 1000000000; i++) {} return null; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous validator | Minimal | 0 | Blocks paint during execution | [X] Bad |
| Light synchronous validator | Minimal | 0 | No blocking, fast paint | [OK] Good |
| Async validator with debounce | Minimal | 0 | Non-blocking, smooth paint | [OK] Good |