Performance: Ref and reactive in Composition API
MEDIUM IMPACT
This affects how Vue tracks changes and updates the DOM efficiently during user interactions.
import { ref, reactive } from 'vue'; const count = ref(0); const user = reactive({ name: 'Alice', age: 30 });
import { reactive } from 'vue'; const count = reactive({ value: 0 }); const user = reactive({ name: 'Alice', age: 30 });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using reactive for primitives | More proxy layers | Multiple re-renders | Higher paint cost | [X] Bad |
| Using ref for primitives | Minimal proxy layers | Single re-render | Lower paint cost | [OK] Good |
| Replacing nested reactive objects | Triggers full reactivity recalculation | Multiple reflows | Higher paint cost | [X] Bad |
| Mutating nested reactive properties | Fine-grained updates | Single reflow | Lower paint cost | [OK] Good |