by fasterdom · 7y ago · 0 comments
The source data sits in an array of objects.
On each update, I need to update the table cells with the latest values from the source array. The content of each cell can change, possibly it's css class too (from red it become blue for example).
I'm using Vue/Bootstrap-Vue table at the moment, but it's quite slow.
Is Svelte suitable for this? Other options to quickly update a <table> from data in an array of objects, one object per row?
It seems to do pretty well! I turned on the FPS meter in Chrome and scrolled around a bunch, and it seems smooth, reporting around ~50fps. It did get my CPU going pretty good, though.
https://svelte.dev/repl/061b958e665c4949bcf831fa5da474c4?ver...
EDIT: The performance is a lot better running as a standalone app (I downloaded the app and ran it locally). Maybe the REPL adds some overhead.
btw, Looks really snappy on my laptop.
I would say his next problem is going to be getting the data fast enough to feed the the UI, a nicely packed websocket protocol would work well I'd guess
E.g. the symbol for "GOOG" stored in a hash table, when GOOG updates; call that hash directly: "symbols[symbol].update(data)" then re-render the cell DOM element.
You really have to profile the code to figure out what's expensive. Maybe there is no scaling wrt. the number of nodes that change because repainting/relayouting is more expensive than updating the DOM.
https://opensource.janestreet.com/incr_dom/
it is built for visualizing HFT, so performance should suffice.
WebAssembly might help you as well.
Source - I work on perspective.
I wrote a couple of hundred lines of vanilla JS. It works fine.
Huh? No, not at all. As far as I understand, React has algorithms that replace only the html that changed in a dom subtree (and that is called virtual dom, not shadow dom, which is a different concept).
But if you already know exactly what has changed and where to change it in the page, there is no need for more complex algorithms to kick in. Just take the pointer to your div or cell and change the content.
Bottom line: React is written in vanilla Javascript. Can't do better than it.
Changing the DOM doesn't cause a full re-render, the browser will optimize the repaints to only the parts that have changed.
People don't understand how the DOM works, and its become a great way to filter out people.
I bet if those 100 rows aren't even in the viewport you can get a big perf boost by only rendering a subset and rendering more when the user scrolls.
We've gotten ~30x boost on our tables with 100s of rows by using a progressive rendering algorithm.
virtualdom - preact/react/vue/snabbdom e.t.c is usually fast for most things. you can diff about a million things under a 10ms timeframe. Rendering a million things is an entirely different ballgame.
I'm using it to mimic Excel-like display of data, and it's pretty responsive, but I'm not at your scale of 10x/sec.
It also supports cell highlighting with different colors, but, unfortunately, doesn't natively support CSS-type classes on cells.
Paste this and run:
<script>
const rows = 100,
cols = 10,
table = Array.from({ length: rows }).map((_, i) => Array.from({ length: cols }).map((_, j) => ({ i, j })));
console.log(table);
setInterval(function() {
let cell = table[Math.floor(Math.random() * rows)][Math.floor(Math.random() * cols)];
cell.i = Math.floor(Math.random() * 100);
cell.j = Math.floor(Math.random() * 100);
}, 1);
</script>
<table>
<tr for="let row of table">
<td for="let cell of row" bind>cell.i + ":" + cell.j</td>
<td></td>
</tr>
</table>
It only updates DOM element textContent on each change.Let's say you slowed it down to 1x per second, you'd increase max possible latency of an updated value being displayed by ~900ms - is that enough time to be important in your application?
See an example on how they look: https://youtu.be/DMz1CZPdI-g?t=437
You still gain a lot of benefits from your component framework this way (composability, life cycle management, easy interop with the rest of the app). It’s more work that you wouldn’t want to do all the time, of course.