DEV Community

Alex Spinov
Alex Spinov

Posted on

Million.js Has a Free React Compiler — Here's How to Use It

React re-renders entire component trees when state changes. Virtual DOM diffing is fast but not free. Million.js replaces React's Virtual DOM with direct DOM manipulation — up to 70% faster.

What Is Million.js?

Million.js is a drop-in compiler that optimizes React components. It analyzes your components at build time and replaces Virtual DOM operations with direct DOM updates.

Quick Start

npm install million
Enter fullscreen mode Exit fullscreen mode
// vite.config.ts
import million from 'million/compiler';
import react from '@vitejs/plugin-react';

export default {
  plugins: [
    million.vite({ auto: true }), // Auto-optimize all components
    react(),
  ],
};
Enter fullscreen mode Exit fullscreen mode

That's it. Your existing React app is now faster. No code changes needed.

How It Works

// Your code stays the same
function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </div>
  );
}

// Million.js compiler transforms it at build time:
// Instead of: Full VDOM diff → find changes → patch DOM
// Million does: Direct DOM update → element.textContent = count
Enter fullscreen mode Exit fullscreen mode

Performance Gains

Scenario React React + Million.js
List re-render (1K items) 45ms 12ms
State update 8ms 2ms
Initial render Same Same
Bundle overhead 0 +3KB

Manual Optimization

For fine-grained control:

import { block } from 'million/react';

const UserCard = block(function UserCard({ name, email, avatar }) {
  return (
    <div className="card">
      <img src={avatar} alt={name} />
      <h2>{name}</h2>
      <p>{email}</p>
    </div>
  );
});
Enter fullscreen mode Exit fullscreen mode

When Million.js Helps Most

  • Data-heavy UIs — dashboards, tables, lists
  • Frequent re-renders — real-time data, animations
  • Large component trees — complex page layouts
  • Low-end devices — mobile browsers, older hardware

Limitations

Million.js works best with:

  • Pure components (no side effects in render)
  • Static structure (conditional rendering may not optimize)
  • Primitive props (objects/arrays work but less optimal)

Framework Support

  • Vitemillion.vite()
  • Next.jsmillion.next()
  • webpackmillion.webpack()
  • Rollupmillion.rollup()

Get Started


Building high-performance React dashboards? My Apify scrapers deliver fast data feeds. Custom solutions: spinov001@gmail.com

Top comments (0)