Fireship · @fireship

High-school student makes React a million times faster

Uploaded June 10, 2023 · Length 2:47

High-school student makes React a million times faster

Summary

High school student improves React performance by 70% with million JS, a hyper-optimized virtual DOM.

  • react performance optimization
  • million js
  • virtual dom
  • javascript framework

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    it is June 10th 2023 and you are

  2. 0:03

    watching the code report there's

  3. 0:04

    millions of great JavaScript Frameworks

  4. 0:06

    in the world today but the most popular

  5. 0:07

    choice is still react even though we

  6. 0:09

    have faster Alternatives like solid

  7. 0:11

    preact and quick that also use jsx one

  8. 0:14

    of react's original Innovations was the

  9. 0:15

    virtual Dom but many modern Frameworks

  10. 0:17

    have moved away from this approach and

  11. 0:19

    Rich Harris the creator of svelte once

  12. 0:20

    called it pure overhead despite this

  13. 0:22

    react will likely still be used on

  14. 0:24

    websites hundreds of years after we're

  15. 0:25

    all dead but today I have some good news

  16. 0:27

    a recent high school graduate named

  17. 0:29

    Aiden by just improved reacts

  18. 0:31

    performance by 70 percent with million

  19. 0:33

    JS which provides a hyper optimized

  20. 0:35

    virtual Dom and chains the original

  21. 0:37

    virtual Dom to the radiator where it

  22. 0:38

    can't cause any problems when I first

  23. 0:40

    saw this my initial thought was no way

  24. 0:42

    there's no way a teenager could

  25. 0:43

    outrender an entire team of top tier

  26. 0:45

    engineers at meta but there are

  27. 0:46

    benchmarks to back up these outrageous

  28. 0:48

    claims like on the gold standard

  29. 0:50

    framework Benchmark it ranks way higher

  30. 0:51

    than react itself and even beats

  31. 0:53

    solid.js and it provides a live demo

  32. 0:55

    where you can compare react and millions

  33. 0:57

    side by side now it's important to point

  34. 0:58

    out that benchmarks don't really

  35. 1:00

    represent real world use cases and the

  36. 1:02

    vast majority of web apps out there will

  37. 1:03

    never get to the point where they have

  38. 1:05

    rendering issues with a JavaScript

  39. 1:06

    framework however it's always fun to do

  40. 1:08

    some premature over optimization anyway

  41. 1:10

    but if you're a highly experienced react

  42. 1:12

    developer you might be wondering what is

  43. 1:14

    the virtual Dom I've never heard of it

  44. 1:15

    well to update things in the UI react

  45. 1:17

    makes a lightweight copy of the Dom

  46. 1:19

    where it can calculate updates faster

  47. 1:21

    and then update everything all at once

  48. 1:22

    it's kind of like finalizing all your

  49. 1:24

    changes on a blueprint before you go

  50. 1:25

    tearing out walls in a building but all

  51. 1:27

    this happens at runtime and there's a

  52. 1:29

    lot of unnecessary work trying to figure

  53. 1:30

    out what changed million JS takes a more

  54. 1:33

    surgical approach by introducing a

  55. 1:34

    compiler that can perform static

  56. 1:36

    analysis to figure out exactly where the

  57. 1:38

    dynamic data is in advance it creates an

  58. 1:40

    edit map to represent the state of the

  59. 1:42

    application which can then determine

  60. 1:43

    what has changed with far less

  61. 1:44

    computation required this approach is

  62. 1:46

    inspired by other Frameworks like svelt

  63. 1:48

    and solid which also rely on a compiler

  64. 1:50

    to achieve these surgical Dom updates

  65. 1:52

    and million was also inspired by the

  66. 1:54

    prior work of a library called block Dom

  67. 1:56

    what's also cool about million is that

  68. 1:57

    it's only four kilobytes and extremely

  69. 1:59

    easy to use use all you do is take an