Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aidenybai/million
Optimize React performance and make your React 70% faster in minutes, not months.
https://github.com/aidenybai/million
best-practices blockdom compiler hacktoberfest memo million millionjs optimization optimize performance preact react react-hooks react-optimize renderer rendering virtual-dom
Last synced: 3 days ago
JSON representation
Optimize React performance and make your React 70% faster in minutes, not months.
- Host: GitHub
- URL: https://github.com/aidenybai/million
- Owner: aidenybai
- License: mit
- Created: 2021-05-29T18:38:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-15T00:32:00.000Z (5 months ago)
- Last Synced: 2024-10-29T21:10:55.499Z (about 1 month ago)
- Topics: best-practices, blockdom, compiler, hacktoberfest, memo, million, millionjs, optimization, optimize, performance, preact, react, react-hooks, react-optimize, renderer, rendering, virtual-dom
- Language: TypeScript
- Homepage: https://million.dev
- Size: 85 MB
- Stars: 16,319
- Watchers: 63
- Forks: 573
- Open Issues: 100
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome - aidenybai/million - Optimize React performance and make your React 70% faster in minutes, not months. (TypeScript)
- my-awesome-list - million
- awesome-projects - million
- awesome-ccamel - aidenybai/million - Optimize React performance and make your React 70% faster in minutes, not months. (TypeScript)
- awesome-github-star - million
- stars - aidenybai/million - Optimize React performance and make your React 70% faster in minutes, not months. (TypeScript)
- awesome - aidenybai/million - Optimize React performance and make your React 70% faster in minutes, not months. (TypeScript)
- awesome-list - million - focused virtual DOM. It's fast! | aidenybai | 1154 | (TypeScript)
- awesome-javascript - Million - <1kb compiler-focused virtual DOM. It's fast! (MVC Frameworks and Libraries / Runner)
- awesome-react - million - An extremely fast and lightweight optimizing compiler (**Awesome React** [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) / React)
- StarryDivineSky - aidenybai/million
- awesome-star-libs - aidenybai / million
README
> Want to **automatically find and fix performance issues**? Check out [Million Lint](https://million.dev/).
## What is Million.js?
Million.js is an extremely fast and lightweight optimizing compiler that make [components](https://react.dev) up to [_**70% faster**_](https://krausest.github.io/js-framework-benchmark/current.html).
> Oh man... Another [`/virtual dom|javascript/gi`](https://regexr.com/6mr5f) framework? I'm fine with [React](https://reactjs.org) already, why do I need this?
Million.js works with React and makes reconciliation faster. By using a fine-tuned, optimized virtual DOM, Million.js reduces the overhead of diffing ([_try it out here_](https://demo.million.dev))
**TL;DR:** Imagine [React](https://react.dev) components running at the speed of raw JavaScript.
### [**👉 Setup Million.js in seconds! →**](https://million.dev/)
## Installation
The Million.js CLI will automatically install the package and configure your project for you.
```bash
npx million@latest
```Once your down, just run your project and information should show up in your command line!
> Having issues installing? [**→ View the installation guide**](https://million.dev/docs/install)
## Why Million.js?
To understand why to use Million.js, we need to understand how React updates interfaces. When an application's state or props change, React undergoes an update in two parts: rendering and reconciliation.
To show this, let's say this is our `App`:
```jsx
function App() {
const [count, setCount] = useState(0);
const increment = () => setCount(count + 1);
return (
Count: {count}
Increment
);
}
```In this `App`, when I click on the button, the `count` state will update and the `
` tag will update to reflect the new value. Let's break this down.
### Rendering
The first step is rendering. Rendering is the process of generating a snapshot of the current component. You can imagine it as simply "calling" the `App` function and storing the output in a variable. This is what the `App` snapshot would look like:
```jsx
const snapshot = App();// snapshot =
;
Count: 1
Increment
```### Reconciliation
In order to update the interface to reflect the new state, React needs to compare the previous snapshot to the new snapshot (_called "diffing"_). React's reconciler will go to each element in the previous snapshot and compare it to the new snapshot. If the element is the same, it will skip it. If the element is different, it will update it.
- The `
` tag is the same, so it doesn't need to be updated. ✅
- The `` tag is the same, so it doesn't needs to be updated. ✅
- The text inside the `` tag is different, so it needs to be updated. ⚠ ️
- The `` tag is the same, so it doesn't need to be updated. ✅
- The `onClick` prop is the same, so it doesn't need to be updated. ✅
- The text inside the `` tag is the same, so it doesn't need to be updated. ✅_(total: 6 diff checks)_
```diff
-Count: 0
+Count: 1
Increment
```From here, we can see that the `
` tag needs to be updated. React will then update the `
` DOM node to reflect the new value.
```jsx
.innerHTML = `Count: ${count}`;
```### How Million.js makes this faster
React is slow.
The issue with React's reconciliation it becomes **exponentially slower** the more JSX elements you have. With this simple `App`, it only needs to diff a few elements. In a real world React app, you can easily have hundreds of elements, slowing down interface updates.
Million.js solves this by **skipping the diffing step entirely** and directly updating the DOM node.
Here is a conceptual example of how Million.js reconciler works:
```jsx
function App() {
const [count, setCount] = useState(0);
const increment = () => setCount(count + 1);// generated by compiler
if (count !== prevCount) {
.innerHTML = `Count: ${count}`;
}.onclick = increment;
// ...
}
```Notice how when the `count` is updated, Million.js will directly update the DOM node. Million.js turns React reconciliation from `O(n)` (linear time) to `O(1)` (constant time).
> How fast is it? [**→ View the benchmarks**](https://krausest.github.io/js-framework-benchmark/current.html)
## Resources & Contributing Back
Looking for the docs? Check the [documentation](https://million.dev) or the [Contributing Guide](https://github.com/aidenybai/million/blob/main/.github/CONTRIBUTING.md) out. We also recommend reading [_Virtual DOM: Back in Block_](https://million.dev/blog/virtual-dom) to learn more about Million.js's internals.
Want to talk to the community? Hop in our [Discord](https://discord.gg/X9yFbcV2rF) and share your ideas and what you've build with Million.js.
Find a bug? Head over to our [issue tracker](https://github.com/aidenybai/million/issues) and we'll do our best to help. We love pull requests, too!
We expect all Million.js contributors to abide by the terms of our [Code of Conduct](https://github.com/aidenybai/million/blob/main/.github/CODE_OF_CONDUCT.md).
[**→ Start contributing on GitHub**](https://github.com/aidenybai/million/blob/main/.github/CONTRIBUTING.md)
![Alt](https://repobeats.axiom.co/api/embed/74a4b271e2a24c2cb08c897cfc1dfe155e0e1c1e.svg 'Repobeats analytics image')
## Codebase
This repo is a "mono-repo" with modules. Million.js ships as one NPM package, but has first class modules for more complex, but important extensions. Each module has its own folder in the `/packages` directory.
You can also track our progress through our [Roadmap](https://github.com/users/aidenybai/projects/5/views/1?layout=roadmap).
| Module | Description |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| [`million`](https://github.com/aidenybai/million/tree/main/packages/million) | The main Virtual DOM with all of Million.js's core. |
| [`react`](https://github.com/aidenybai/million/tree/main/packages/react) / [`react-server`](https://github.com/aidenybai/million/tree/main/packages/react-server) | React compatibility for Million.js. |
| [`compiler`](https://github.com/aidenybai/million/tree/main/packages/compiler) | The compiler for Million.js in React. |
| [`jsx-runtime`](https://github.com/aidenybai/million/tree/main/packages/jsx-runtime) | A simple JSX runtime for Million.js core. |
| [`types`](https://github.com/aidenybai/million/tree/main/packages/types) | Shared types between packages |## Sponsors
## Acknowledgments
Million.js takes heavy inspiration from the following projects:
- [`blockdom`](https://github.com/ged-odoo/blockdom) ([Géry Debongnie](https://github.com/ged-odoo))
Thank you to Géry pioneering the concept of "blocks" in the virtual DOM. Many parts of the Million.js codebase either directly or indirectly derive from his work.
- [`voby`](https://github.com/vobyjs/voby) ([Fabio Spampinato](https://github.com/fabiospampinato))
The Million.js "template" concept is derived from Voby's `template()` API.
- [Hack the Wave](https://hackthewave.com) ([Melinda Chang](https://github.com/melindachang)) for their homepage.
- [`react`](https://react.dev) and [`turbo`](https://turbo.build) for their documentation. Many parts of the current Million.js documentation are grokked and modified from theirs.
- [`ivi`](https://github.com/localvoid/ivi), [Preact](https://github.com/preactjs/preact), [and more](https://krausest.github.io/js-framework-benchmark/2021/table_chrome_96.0.4664.45.html)## License
Million.js is [MIT-licensed](LICENSE) open-source software by [Aiden Bai](https://aiden.mov) and [contributors](https://github.com/aidenybai/million/graphs/contributors):