Performance: Typing ref and reactive
MEDIUM IMPACT
Typing refs and reactive objects affects how Vue tracks changes and updates the DOM, impacting rendering speed and responsiveness.
import { ref } from 'vue'; const count = ref<number>(0);
import { ref } from 'vue'; const count = ref(null); count.value = 0;
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Untyped ref | Reactive tracking on all changes | Multiple reflows on updates | Higher paint cost due to redundant updates | [X] Bad |
| Typed ref | Optimized reactive tracking | Single reflow per update | Lower paint cost with batched updates | [OK] Good |
| Untyped reactive object | Deep reactive tracking triggers many updates | Multiple reflows on nested changes | High paint cost due to layout thrashing | [X] Bad |
| Typed reactive object | Selective reactive tracking | Minimal reflows on relevant changes | Reduced paint cost with efficient updates | [OK] Good |