Giter Site home page Giter Site logo

jahirfiquitiva / million Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aidenybai/million

0.0 0.0 0.0 80.24 MB

Optimize React performance and make your React 70% faster in minutes, not months.

Home Page: https://million.dev

License: MIT License

JavaScript 8.87% TypeScript 71.85% CSS 1.23% HTML 0.02% MDX 18.03%

million's Introduction

Million.js Banner

What is Million.js?

Million.js is an extremely fast and lightweight optimizing compiler that make components up to 70% faster.

Oh man... Another /virtual dom|javascript/gi framework? I'm fine with React 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)

TL;DR: Imagine React components running at the speed of raw JavaScript.

Installation

The Million.js CLI will automatically install the package and configure your project for you.

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

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:

function App() {
  const [count, setCount] = useState(0);
  const increment = () => setCount(count + 1);
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>Increment</button>
    </div>
  );
}

In this App, when I click on the button, the count state will update and the <p> 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:

const snapshot = App();

// snapshot =
<div>
  <p>Count: 1</p>
  <button onClick={increment}>Increment</button>
</div>;

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 <div> tag is the same, so it doesn't need to be updated. โœ…
    • The <p> tag is the same, so it doesn't needs to be updated. โœ…
      • The text inside the <p> tag is different, so it needs to be updated. โš  ๏ธ
    • The <button> 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 <button> tag is the same, so it doesn't need to be updated. โœ…

(total: 6 diff checks)

<div>
-  <p>Count: 0</p>
+  <p>Count: 1</p>
  <button onClick={increment}>Increment</button>
</div>

From here, we can see that the <p> tag needs to be updated. React will then update the <p> DOM node to reflect the new value.

<p>.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:

function App() {
  const [count, setCount] = useState(0);
  const increment = () => setCount(count + 1);

  // generated by compiler
  if (count !== prevCount) {
    <p>.innerHTML = `Count: ${count}`;
  }

  <button>.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

Resources & Contributing Back

Looking for the docs? Check the documentation or the Contributing Guide out. We also recommend reading Virtual DOM: Back in Block to learn more about Million.js's internals.

Want to talk to the community? Hop in our Discord and share your ideas and what you've build with Million.js.

Find a bug? Head over to our issue tracker 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.

โ†’ Start contributing on GitHub

Alt

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.

Module Description
million The main Virtual DOM with all of Million.js's core.
react / react-server React compatibility for Million.js.
compiler The compiler for Million.js in React.
jsx-runtime A simple JSX runtime for Million.js core.
types Shared types between packages

Sponsors

Acknowledgments

Million.js takes heavy inspiration from the following projects:

License

Million.js is MIT-licensed open-source software by Aiden Bai and contributors:

million's People

Contributors

aidenybai avatar dependabot[bot] avatar tobysolutions avatar willdoescode avatar aslemammad avatar quiibz avatar sukkaw avatar ftonato avatar cbbfcd avatar johnjyang avatar poteboy avatar oliverloops avatar nisargio avatar lalitkumawat1m avatar sukritmalpani avatar uzairnoman avatar haideralipunjabi avatar timonwa avatar nojiritakeshi avatar eniodev avatar exuanbo avatar rakshixh avatar destroyer22719 avatar roar022 avatar drex72 avatar jasonappah avatar eltociear avatar abhiprasad avatar 38elements avatar olaoluwaayanbola avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.