Re-renders are cheap
React avoids expensive DOM operations using diffing and reconciliation—and why most re-renders are not a performance problem.
🧩 Introduction

Most developers hear this:
👉 “Re-renders are cheap”
And they think:
But here’s the truth:
👉 Re-rendering is cheap
👉 DOM updates are expensive
So the real question is:
👉 What is React actually doing during a re-render?
Let’s break it down.
🧩 The Big Myth

Many people assume:
👉 React compares the entire DOM on every update
If that were true…
❌ React would be painfully slow
What React actually does:
👉 It avoids full comparison
👉 It uses a tree-based strategy
Instead of this:
❌ Compare EVERYTHING
React does this:
✅ Compare only what matters
This is where Diffing comes in.
🧠 What is Diffing?
Diffing =
👉 Comparing previous UI tree vs new UI tree
But not randomly.
React follows strict rules.
🧩 Diffing Rules

React does NOT guess.
It uses predictable rules:
1. Same Type → Update
html
<div> → <div>👉 React keeps the node
👉 Updates only changed props
2. Different Type → Replace
html
<div> → <span>👉 React destroys old node
👉 Creates a new one
3. Lists → Use Keys
👉 React matches elements by keys
👉 Efficiently moves/updates items
Key Insight:
React checks:
- Type
- Position
- Keys
Not full DOM equality.
🧩 Same Type (Cheap Path)

Example:
javascript
<Button label="Save" />
<Button label="Update" />What happens:
👉 Same component type
👉 React reuses the node
👉 Only updates props
Why this is fast:
- No DOM destruction
- No remounting
- Just patching
👉 This is the cheap path
🧩 Different Type (Expensive Path)

Example:
html
<div> → <section>What happens:
👉 React cannot reuse
👉 It destroys old node
👉 Creates a new one
Cost:
- Unmount old tree
- Lose state
- Mount new tree
👉 This is the expensive path
🧠 Now Comes the Real Engine
Diffing only finds differences.
👉 It does NOT update the UI.
That job belongs to:
⚙️ Reconciliation
🧩 Reconciliation Flow

Flow:
- Old Tree
- Diffing
- Patch Instructions
- Updated UI
What React does:
👉 It calculates the minimal set of changes
Example instructions:
- Update text
- Replace node
- Keep node
Then…
👉 It applies them in the commit phase
One-line definition:
👉 Reconciliation = applying the smallest possible changes
🧩 Why It’s Fast (O(n))

React does NOT compare everything.
👉 It traverses the tree once
Complexity:
👉 O(n) — linear time
Why this matters:
- Work grows with component size
- Not entire DOM size
👉 This is why React scales.
🧠 The Big Insight
React is not “smart AI”.
It is:
👉 predictable + constrained + optimized
It trades perfect accuracy for speed.
And that’s what makes it fast.
🧩 Why Re-renders Are Cheap

During re-render:
👉 React mostly works in memory
What happens:
- Runs component functions
- Builds new virtual tree
- Compares with old tree
What does NOT happen (usually):
❌ No DOM updates
❌ No repaint
👉 DOM is touched ONLY when necessary
🧩 Real Cost

Let’s be very clear:
Cheap:
- JavaScript execution
- Virtual tree comparison
Expensive:
- DOM mutations
- Layout + repaint
👉 That’s the real bottleneck.
Mental Model:
plain text
Render phase → Cheap
Commit phase → Expensive🧠 Why Most Devs Get This Wrong
They see:
👉 “Component rendered again”
And think:
❌ Performance issue
But the real question is:
👉 Did the DOM actually change?
If not:
👉 There is NO problem.
🧩Final Understanding

Now everything connects:
React’s strategy:
- Same type → update
- Different type → replace
- Reconciliation → minimal changes
- DOM updates → minimized
Final Truth:
👉 Re-render is NOT the problem
👉 Unnecessary DOM work is
🎯 Final Takeaways
- React does NOT compare full DOM
- It uses tree-based diffing
- It applies minimal patches
- It avoids DOM work whenever possible
One-line clarity:
👉 React is fast because it updates less, not because it renders less.
🔥 Mindset Shift
❌ “Too many re-renders = bad”
✅ “Too many DOM updates = bad”
🚀 What You Just Learned
You now understand:
- Diffing (how React compares)
- Reconciliation (how React updates)
- Why re-renders are cheap
- Where real performance cost lies
🔜 Next Post Teaser
Keys and List Rendering
👉 Why keys are critical
👉 What breaks without them
