4 ms·
Please read this blog post titled "How to win in Web Framework Benchmarks" https://medium.com/@localvoid/how-to-win-in-web-framework-benchmarks-8bc31af76ce7 htt
by dmitriid 8y ago
Please read this blog post titled "How to win in Web Framework Benchmarks" https://medium.com/@localvoid/how-to-win-in-web-framework-benchmarks-8bc31af76ce7 https://medium.com/@localvoid/how-to-win-in-web-framework-be...
It goes into some details how different approaches in different frameworks work, and why. Moreover, it shows how you basically need to re-implement Virtual DOM and other tricks in vanilla JS code to approach the same speed.
Yes, browser engineers are not that stupid. But they don't batch operations as efficiently as a proper Virtual DOM implementation would (including efficiently handling event listeners, looking for clues like `keys` on repeating DOM elements etc. etc.).
- stupidcar 8y agoThat article doesn't quite support what you're claiming. The Vanilla JS implementation uses optimised DOM mutation techniques that are inspired by how the Virtual DOM libraries do things, but it doesn't re-implement a Virtual DOM. Yet it's faster than any of the Virtual DOM implementations its benchmarked against. So the takeaway is that DOM mutation can be slower or faster depending on the techniques you use. Using a Virtual DOM library can help you improve performance, because these techniques are often baked in, but they don't intrinsically result from using a Virtual DOM: You could write a V-DOM library that didn't use them, and was slow, and you could write, for example, a static template library that did, and was fast. In theory, a compiled, static template approach should be faster than V-DOM (or anything other than a set of totally bespoke and optimised vanilla JS functions for each app operation). Because while a compiled template does not have the turing-complete flexibility of something like JSX, it has the advantage of knowing in advance exactly which parts of the DOM can change and how, which eliminates the need to build and diff the Virtual DOM tree.
- localvoid 8y ago> In theory, a compiled, static template approach should be faster than V-DOM Maybe faster in basic microbenchmarks. As soon as you start optimizing UI library for complex applications, there are many other optimization goals you should focus on, like the size of the generated code per component type, the amount of different code paths(increase probability that executed code is JITed), etc. Virtual DOM solves many issues, it is not just diffing, it is also a lightweight component model, possibility to add lightweight synthetic events, single code path for creating/updating/destroying DOM nodes, the simplest algo that handles complex tree transformations, etc.
- naasking 8y ago> Moreover, it shows how you basically need to re-implement Virtual DOM and other tricks in vanilla JS code to approach the same speed. Surplus [1] is the fastest in most benchmarks, and it doesn't use a virtual DOM. [1] https://github.com/adamhaile/surplus https://github.com/adamhaile/surplus
- localvoid 8y agoCouple of small changes to the surplus benchmark implementation[1], and it is not the fastest anymore[2] even when benchmark is super biased towards fine-grained direct DOM manipulation libraries like surplus (ratio of data binding per DOM elements ~0.5, number of DOM elements 8000-80000) 1. https://github.com/localvoid/js-framework-benchmark/commit/1b661140d4a1a94ba36df385d4970678aed13402 https://github.com/localvoid/js-framework-benchmark/commit/1... 2. http://rawgit.com/localvoid/js-framework-benchmark/sandbox/webdriver-ts-results/table.html http://rawgit.com/localvoid/js-framework-benchmark/sandbox/w...
- naasking 8y agoI'm not sure what table you're looking at, but at those links Surplus is still the fastest only behind vanilla JS.
- localvoid 8y agohttps://i.imgur.com/MG3eGTM.png https://i.imgur.com/MG3eGTM.png Inferno here is also slightly patched[1], instead of using stateless components, it is using stateful components to demonstrate how fast it can go down when you start using high-level abstractions in a library that focuses only on low-level primitives. And if you really want to understand the fundamental flaw in libraries with fine-grained direct data bindings, try to reimplement this[2] 70 lines of React code with such library. 1. https://github.com/localvoid/js-framework-benchmark/commit/225eff5c53eb800599eb979d1f402f30d308a916 https://github.com/localvoid/js-framework-benchmark/commit/2... 2. https://github.com/localvoid/uibench-react/blob/master/js/fc.jsx https://github.com/localvoid/uibench-react/blob/master/js/fc...