FS logo

Farhaan Shaikh

FS Blogs

HomeBlogsSubscribe

FS Blogs

Notes on building, shipping, and learning in public.

Essays, experiments, and honest lessons from the work behind this blog.

New posts, no noise.

One short email when something new is published.

No spam. Only new posts.

←Back to blogs

Re-renders are cheap

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

🧩 Introduction

Blog image

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

Blog image

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

Blog image

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)

Blog image

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)

Blog image

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

Blog image

Flow:

  1. Old Tree
  2. Diffing
  3. Patch Instructions
  4. 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))

Blog image

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

Blog image

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

Blog image

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

Blog image

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

Post details

Published

Apr 10, 2026

Updated

Mar 31, 2026

Read time

6 min read

Tags

ReactTutorialGuideBest PracticesTechnical

Related posts

Why React Hooks Break?
ReactApr 17, 2026
Why React Hooks Break?Technical

Why React Hooks Break?

A deep dive into how React tracks hooks internally using an indexed system—and why breaking hook order causes bugs, crashes, and chaos.

Open article→
SetState feels broken
ReactApr 15, 2026
SetState feels brokenTechnical

SetState feels broken

React handles state updates internally—why setState is asynchronous, how batching works, and why your state sometimes feels “wrong”.

Open article→
Using index as keys
ReactApr 13, 2026
Using index as keysTechnical

Using index as keys

Why using index as key causes subtle bugs, and how to fix it using stable identities.

Open article→