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.
They are basically free when you have this little data. 1k cells updates 10 times a second means that you have around 100 micro seconds per cell, you can do thousands of lookups in that time. The only things which could even come close to costing 100 micro seconds are if you accidentally re-flow the html each cell update, re-render the html each cell update, send a http request each cell update or if you go through all the data each cell or the framework you are using is extremely inefficient or other unnecessary work. Each of those are easily fixable by doing the html and javascript by hand instead of using frameworks.
https://opensource.janestreet.com/incr_dom/
it is built for visualizing HFT, so performance should suffice.
Not a problem for a single layout pass, but a performance problem if the data changes every frame.
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.
You should watch "Rethinking reactivity" on YouTube.
React is using Virtual DOM, which is not free. It is fast, but it is not free.
Of course, that's what I meant- maybe it wasn't clear. React can't be faster than vanilla js, it's written in vanilla js after all.
The whole virtual dom's purpose is to calculate the smallest possible update when you don't know (and don't care) what exactly has changed in your view. But that calculation of course has a cost. And if you know very well what changed and where, like in the case of the GP, nothing can be faster than changing it directly.
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.
> I wouldn't even know where to start to allow clicks and such.
Figuring that out should be a good exercise, then. Otherwise, you might want to use some library building on top of canvas.
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?