Better HN
topnewbestaskshowjobs
Log inSign up

localvoid

75 karma · joined Sep 19, 2014 (12y ago) · 61 submissions

Submissions

comment 8y ago · link · parent

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/2...

2. https://github.com/localvoid/uibench-react/blob/master/js/fc...

comment 8y ago · link · parent

Couple 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/1...

2. http://rawgit.com/localvoid/js-framework-benchmark/sandbox/w...

comment 8y ago · link · parent

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

comment 8y ago · link · parent

> making separate implementations no longer necessary

Until you actually start to implement gesture disambiguation and realize that pointer events are useless [1][2]

1. https://github.com/w3c/pointerevents/issues/178

2. https://github.com/w3c/pointerevents/issues/216

comment 8y ago · link · parent

> 1. benchmarks have zero information value

Statements without any proof is more valuable than "benchmarks with zero information value"?

> what I mean is that compiled templates are usually much faster than doing vdom diffing

If they are usually much faster, why it is so hard to make them perform faster than vdom libraries in this benchmark? Or maybe any other benchmark, please just show me something that I can measure.

comment 8y ago · link · parent

> Since there hasn't been nearly as much effort put into alternative algorithms

Angular2+ team is actually have done an awesome job at experimenting in this problem space. And they've moved away from generating code that is similar to what Svelte does long time ago.

comment 8y ago · link · parent

> so that it doesn't have to do any expensive VDOM diffs.

I am wondering, how is it possible that such non-expensive algorithm is more expensive than many VDOM libraries in this benchmark[1] ?

1. https://rawgit.com/krausest/js-framework-benchmark/master/we...

comment 8y ago · link · parent

> They have virtually nothing in common.

If you think so, then there is really nothing to discuss ;)

comment 8y ago · link · parent

Lifecycles has nothing to do with vdom. Even web components has lifecycle hooks https://developer.mozilla.org/en-US/docs/Web/Web_Components/...

Have you tried to build a components library, or have you seen any component libraries that is built on top of a framework that doesn't provide lifecycle hooks for components? Something like https://ant.design/docs/react/introduce or https://developer.microsoft.com/en-us/fabric#/components

comment 8y ago · link · parent

> It's inherently memory intensive

Even if we pretend that other architectures doesn't have any memory overhead, vdom memory overhead in a large UI app will be less than a single small decoded image. But in reality, KVO can be way much more memory intensive, especially when we consider cases that involve filtering items in large collections.

comment 8y ago · link · parent

> but that changes are tracked with a data reactivity library reminiscent of knockout called s.js instead

Surplus is fast because it doesn't have many features that available in many other libraries. For example, component model with lifecycles.

In this benchmark, "select row" should be the best case scenario for library like this, but even in such scenario it is slower than some vdom libraries.

comment 9y ago · link · parent

I haven't talked about Moon, don't know too much about it. Just wanted to say that small size doesn't always mean that it will have low TTI.

And Moon is small because it doesn't have features that are necessary to build complex apps. For example, keyed updates :)

comment 9y ago · link · parent

> This is really great to see the emphasis on static vs dynamic parts in templates. Polymer, Glimmer, and some other template systems make the distinction between static and dynamic content, but React and most other vdom libraries don't.

https://github.com/facebook/react/issues/3226

All other "static" optimizations doesn't make any noticeable difference in performance in highly optimized vdom libraries. In fact, they are usually decrease overall performance because of increased implementation complexity.

comment 9y ago · link · parent

But many libraries that has a primary focus on library size are usually sacrificing runtime performance to reduce size. Yes, they've reduced parse time, but significantly increased bootstrap time.

I understand that they are doing it because of marketing reasons, because many people think that smaller means faster.

comment 9y ago · link · parent

He tried to solve performance problems in complex applications, and obviously complex applications doesn't need to preserve internal state when children list is changing :)

comment 9y ago · link · parent

>They probably are faster than vanilla code that you'd be able to write on your own, but that says more about your abilities than the performance of frameworks.

I won't be able to write efficient vanilla code for something even slightly more complicated than this benchmark, and I wrote one of the fastest virtual dom implementations out there, so what you expect from an average web developer?

comment 9y ago · link · parent

https://community.oracle.com/blogs/kgh/2004/10/19/multithrea...

comment 9y ago · link · parent

Also, it seems that many people are defending WCs with an argument about interoperability. But in reality, if we start adding components that are using different frameworks, there will be problems with layout thrashing, etc, because there is no standard scheduling APIs, and each framework implements its own scheduler to batch reads and writes https://github.com/ampproject/amphtml/blob/8a76ee942f329179d...

comment 9y ago · link · parent

I also curious to see how web components will be faster than simple javascript objects :)

React apps are usually built with many layers of components that returns another components. And with standard Web API, there will be significantly more DOM nodes because each component is a DOM node.

comment 9y ago · link · parent

Nobody cares when it is 6ms instead of 3ms for partial updates. What is really important is how fast you can create and remove huge amount of nodes (switching pages in SPA, etc), because it is already takes a huge amount of time, and Binding.scala just adds a huge overhead to this cases.

comment 10y ago · link · parent

uibench results on Chrome 54 with full render time and disabled sCU: https://cdn.rawgit.com/localvoid/6715c4b23eadc460112e671b4ad...

comment 10y ago · link · parent

>Creating elements with the DOM API is faster than innerHTML roughly by a factor of 4 on Chrome Canary last I benchmarked it

yes, almost by a factor of 4 :D

check out "render" test cases:

https://cdn.rawgit.com/localvoid/dd96890b82f1d1268df34330b14...

comment 10y ago · link · parent

It depends on the code base. When I've migrated from js code base with 100% gcc type coverage to TypeScript, gcc(without tsickle) in advanced mode stopped rewriting many methods into simple functions, didn't minified many symbols, with 100% type coverage gcc minified all symbols.

When I've tried synthetic UI benchmarks, code with 100% type coverage on desktop machines had the same performance, on old mobile phones it was 0-10% faster(depends on the use case).

Minified code size with 100% type coverage were slightly smaller on small projects, but with the API for building UI Components that I've used, minified code with 100% type coverage should be significantly smaller on a large project.

comment 10y ago · link · parent

There also an amazing tool[0] that processes TypeScript and adds JSDoc annotations for closure compiler, so it can optimize way much better[1]

[0]: https://github.com/angular/tsickle

[1]: https://github.com/google/closure-compiler/wiki/Type-Based-P...

comment 10y ago · link · parent

All libraries in uibench have batching, and batching doesn't improve performance, it just prevents from doing unnecessary work during one frame. It is pointless to test performance of different state changes with enabled batching.

comment 10y ago · link · parent

Preact is using implicit dom recycling, so it heavily breaks use cases like "tree/[*]/render". Just hold mouse over its time and it will display "max" time, it will be much closer to reality.

All other libraries either don't have any form of recycling dom nodes, or it is disabled for this benchmark.

comment 10y ago · link · parent

In a real application, you'll need to deal with moving elements, document shape will be changing, etc. Trying to solve this cases is the most complicated part of vdom libraries. If you try to do naive replace/update, it will be significantly slower.

comment 10y ago · link · parent

>Let's be clear, manually updating the DOM is as optimized as you can possibly be. Virtual-DOM isn't somehow magically more efficient than direct, imperative manipulation of the DOM.

The actual problem is how to efficiently traverse/modify DOM structure, in the end you'll just reimplement virtual dom.

comment 11y ago · link · parent

>Virtual DOM approaches never really were about performance.

"React abstracts away the DOM from you, giving a simpler programming model and better performance" https://github.com/facebook/react

It seems strange to me that many developers are now trying to convince everyone that vdom wasn't selling as a way to get better performance. Yes, getting rid of data changes over time is important property of vdom approaches, but when all this vdom hype were started, everyone is also talked how awesome it is in terms of performance.

comment 11y ago · link · parent

Don't look at "overall time" to compare performance, I've added it just because some of the vdom library devs asked it, so they can easily track regressions/improvements in their libraries. Numbers in this benchmark aren't so useful if you aren't a vdom developer, some libraries were broken(the last time I've checked), some using caching to get ridiculous render times, etc.

>Is that argument correct? Is reading the DOM actually not so problematic, as long as the modification you make to it are minimal (which seems to be the strategy here)?

If you want to squeeze out as much "performance" as it is possible, most of the time you'd want to avoid reading DOM (even simple reads, not something that triggers render/layout)

And when it comes to minimal number of modifications, most popular libraries even fail on cases like "moveFromEndToStart or moveFromStartToEnd" (depends on the direction they traverse DOM), they will make N-1 moves.

But in the end all this numbers doesn't matter too much, React is fast enough for most use cases, its community and ecosystem is way more important than numbers in this benchmark.

123