Performance: Reactive Map and Set
MEDIUM IMPACT
This affects how Vue tracks changes in Map and Set collections, impacting update speed and rendering responsiveness.
const myMap = ref(new Map()); // Batch updates by replacing the Map const tempMap = new Map(); for (let i = 0; i < 100; i++) { tempMap.set(i, i * 2); } myMap.value = tempMap;
const myMap = reactive(new Map()); // Updating inside a loop for (let i = 0; i < 100; i++) { myMap.set(i, i * 2); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple individual Map.set() calls | Many reactive triggers | 1 reflow (batched) | Medium paint cost | [X] Bad |
| Batch Map replacement | Single reactive trigger | Single reflow | Low paint cost with one update | [OK] Good |
| Multiple individual Set.add() calls | Many reactive triggers | 1 reflow (batched) | Medium paint cost | [X] Bad |
| Batch Set replacement | Single reactive trigger | Single reflow | Low paint cost | [OK] Good |