Comparing React to Vue for dynamic tabular data
engineering.footballradar.com
engineering.footballradar.com
On the extreme end of things, we have lists that contain several thousand items that update a few elements that are potentially updating up to ten times a second. The biggest being the member list on a server. One of our servers has ~6500 online right now, with people coming online/offline/away every second, changing their current game, typing, etc...
Few lessons we've learned: 1) Don't use ImmutableJS for small objects with a few keys containing scalar values, it's too slow. It's actually faster to just a) copy objects ({...oldValues, newKey: newValue}) or b) re-use objects and power shouldComponentUpdate in another fashion. In some cases, we use an "object version" that is incremented every time the object is actually updated. Then compare that in shouldComponentUpdate. 2) Only render what's visible. In our lists, each item has a fixed height, so we only render elements that are visible. This cuts down from having to render 6500 items in that list, to a good 20-30.
Here's the implementation without ImmutableJS:
https://github.com/guscost/VueReactPerf
Note: Using version tags with shouldComponentUpdate is a great way to optimize for speed, but then you're responsible for updating all your versions manually. If you forget one, the component will "freeze" and you may spend some time tracking down the problem. Just a friendly reminder that immutable data and unoptimized components are both better in this respect.
silly me! Apologies!
You're definitely right to point out that Immutable.js is really not always what you want for small values that change all the time. Immutable.js collections are best used for just that: collections. If you have to copy an array or map with a ton of entries to make a change, it's going to be super slow - Persistent Immutable data structures can help with that.
But I agree with your conclusion that any JS objects that are being used as small tuples are definitely better off staying plain JS objects.
You also don't have to use all Immutable.js or nothing at all. Similar to how using an ES6 Map collection means you don't have to stop using JS objects. Use Immutable collections where they offer benefits, but spreading it everywhere is not a performance panacea, as you rightly discovered.
When I was typing out the original reply, I meant to say "Don't use Immutable.JS for small objects" but ended up putting a period in the middle... which could have led to some confusion. I've edited it to make it more clear.
We've also had some perf issues with using Immutable JS for even larger arrays. I think paying the cost of shallow copying the entire array when modifying it ended up winning in the long run as our render functions could loop over the array much faster.
I'm curious how you keep track of visibility? I have a React app that does something similar to this by checking on scroll, but I kept getting killed by the browser having to check layout so many times on scroll, even if I throttled the event listener.
Dev du -h -d 1 VueReactPerf/
1,2G VueReactPerf/node_modules
2,0M VueReactPerf/dist
52K VueReactPerf/src
1,7M VueReactPerf/.git
1,2G VueReactPerf/
=> 1.2 GB of dependencies. What is happening to the JS ecosystem, where displaying a table in HTML needs 1.2 freaking Gigabytes ?Web dev has exciting things going on in it, but it feels mostly like a bunch of children with no concept of consequences running around desperately re-inventing wheels, rather than caring about quality, efficiency, diligence and professionalism.
It's fucking disgraceful, and we should be ashamed of it.
$ git clone https://github.com/footballradar/VueReactPerf
$ cd VueReactPerf/
$ npm install
$ du -h -d 1
820K ./.git
1.9M ./dist
133M ./node_modules
16K ./srcI've been playing with electron (unfortunately based on Node), and the "npm install" installs a lot of 20 line node packages to do really small things. I think these guys took the unix philosophy of do one thing and do it right to such an unpractical extreme.. But I guess that you can't do any better when all your formal studies were 5 months in codeacademy and the like..
We'll re-run the tests in the morning (uk) and post the updates.
Good to know react isn't as bad as how it's painted here! (I'll see myself out).
I'm intrigued as to whether that would make a difference overall and whether there is any difference between the frameworks when using ABP.
Difference is likely insignificant, but if React is not touching the DOM unless it needs to, does it actually lead to a performance benefit when a user is running an ad blocker (constantly parsing page changes etc).
I'm sure Immutable is pretty well optimized, but you still have overhead from all those function calls and iterating through the array of keys manually.