Under The Hood
frontend vue Vue 3.2+

Vue v-memo: skipping DOM patch work

Last updated
Prerequisites:
Vue template basics
Basic understanding of the virtual DOM patch process
  • vue
  • v-memo
  • rendering
  • virtual-dom
  • patch
  • performance

Read at your depth

The practical view

v-memo="[deps]" tells Vue: if every value in the deps array is identical (Object.is) since the last render, reuse the rendered virtual nodes of this block and skip the diff/patch entirely. Typical usage: v-for with v-memo="[item.id, item.updatedAt]" so a row only re-renders when its own data changed: <div v-for="item in items" :key="item.id" v-memo="[item.id, item.updatedAt]">. The deps array is compared with shallow equality against the previous render's values. When a dependency changes, the whole block re-renders and the memo caches the new values.

The same idea in other frameworks

react equivalent
// memo() on the row component compares props shallowly
const Row = memo(RowView);
// or skip work in the parent with useMemo for the list

Legacy vs modern

Large list without v-memo vs with v-memo

Without v-memo every render re-diffs all rows; with v-memo each row costs one shallow compare of its memo deps when nothing changed.

before → after
Full re-diff
<div v-for="item in items" :key="item.id"> <!-- ❌ OLD: no v-memo → every row re-diffs each tick -->
  <p>{{ item.title }}</p>
</div>
v-memo per row
<div v-for="item in items" :key="item.id"
     v-memo="[item.id, item.likes]" <!-- ✅ NEW: skip patch when [id, likes] unchanged -->
  <p>{{ item.title }}</p>
</div>

Interview gotchas

Context

Interviewers use this to check whether the candidate understands the two bailout levels in Vue: component props comparison vs template-block memo.

The mechanical answer

v-memo skips the vnode diff for a template block; memoized components skip the whole component render when props are shallowly equal. If the row itself is a component with expensive setup/effects, memo() on the component is the better lever because it avoids re-running the render function and lifecycle entirely. v-memo shines for large flat lists of cheap rows where component overhead per row would itself be wasteful. The wrong use is putting v-memo around a block that reads many reactive sources — the deps array grows, the compare cost approaches the patch cost, and you risk stale output if you miss a source.

Trap

The trap answer is 'v-memo is like memo()'. They operate at different layers — one is a template patch optimization, the other is a component render bailout — and v-memo has a correctness hazard memo() does not: memo() compares props automatically, while v-memo trusts your deps array completely. Missing a dependency silently freezes that part of the UI, which is the failure interviewers want you to name.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.