Performance: Watchers for side effects
MEDIUM IMPACT
This affects interaction responsiveness and visual stability by triggering code when reactive data changes.
watch(() => largeReactiveObject, async (newVal) => { await nextTick(); requestIdleCallback(() => { updateDOM(newVal); }); }, { deep: true });
watch(() => largeReactiveObject, (newVal) => {
// heavy synchronous processing
for (let i = 0; i < 1000000; i++) {
// simulate expensive task
}
updateDOM(newVal);
}, { deep: true });| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous watcher work | Multiple DOM updates | Multiple reflows triggered | High paint cost due to blocking | [X] Bad |
| Deferred watcher side effects | Batched or deferred DOM updates | Single or no reflows during interaction | Low paint cost, smooth rendering | [OK] Good |