Performance: Array and object reactivity gotchas
MEDIUM IMPACT
This affects how quickly the UI updates when arrays or objects change, impacting interaction responsiveness and visual stability.
let items = [1, 2, 3]; items[0] = 10; items = items; // Reassignment triggers reactivity
let items = [1, 2, 3]; items[0] = 10; // Direct mutation // No reassignment, so UI does not update
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct mutation without reassignment | No DOM update triggered | 0 reflows but stale UI | No paint triggered | [X] Bad |
| Mutation followed by reassignment | Minimal DOM update triggered | 1 reflow per update | Paint triggered for changed nodes | [OK] Good |
| Replacing entire array/object | DOM updates as needed | 1 reflow per update | Paint triggered for changed nodes | [OK] Good |