Performance: h function for creating vnodes
MEDIUM IMPACT
This affects how Vue creates virtual DOM nodes, impacting rendering speed and memory usage during component updates.
import { h } from 'vue'; const items = ['Item 1', 'Item 2', 'Item 3']; export default { render() { return h('div', {}, items.map(item => h('p', {}, item))); } };
import { h } from 'vue'; export default { render() { return h('div', {}, [ h('p', {}, 'Item 1'), h('p', {}, 'Item 2'), h('p', {}, 'Item 3') ]); } };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual multiple h calls without abstraction | Many vnode creations | Multiple reflows on updates | Higher paint cost due to frequent DOM changes | [X] Bad |
| Using array map to batch vnode creation | Fewer vnode creations, batched | Single reflow per update batch | Lower paint cost with minimal DOM changes | [OK] Good |