Performance: Render functions vs templates decision
MEDIUM IMPACT
This affects how Vue compiles and renders components, impacting initial load time and runtime rendering speed.
<template> <div class="container"> <p>Hello {{ name }}</p> <ul> <li v-for="item in items" :key="item">{{ item }}</li> </ul> </div> </template>
import { h } from 'vue'; export default { render() { return h('div', { class: 'container' }, [ h('p', 'Hello ' + this.name), h('ul', this.items.map(item => h('li', item))) ]) } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Templates for most components | Minimal and optimized by Vue | Few reflows due to efficient updates | Low paint cost | [OK] Good |
| Handwritten render functions for simple UI | Same DOM operations but more complex code | Same reflows but harder to maintain | Low paint cost | [!] OK |
| Render functions for complex conditional logic | Fewer DOM operations by precise control | Reduced reflows | Lower paint cost | [OK] Good |
| Render functions for static content | Same DOM operations but larger bundle | Same reflows | Low paint cost | [X] Bad |