by Jasper_ · 7y ago · 0 comments
This shot from Super Mario Galaxy simulates around 3,000 particles, on top of all the other bone/joint animations that are happening. Performance like this is possible in a web browser, but you wouldn't think so given how popular React and ThreeJS are.
https://noclip.website/#smg/AstroGalaxy;AAI4t49Qk^u9Ld&YUm,m...
Updating the state of thousands of DOM nodes at a steady 16ms per frame in a browser is hard enough that you have to go beyond "just update them all every frame" like in a simple particle system. To go fast you have to move to working out what needs to update based on what changed in the state.
Most web app developers don't want to have to think too hard about how it gets on the screen. They, very reasonably in my opinion, want to work on the app logic itself instead. Unfortunately that's how we end up with janky UIs. If React's concurrent mode can just be fast by default by spreading out updates if the framerate is falling that's good for everyone.
No, it's really not. I've done it before, and profiled it. 16ms is a super long time to a computer. You should easily be able to update tens, if not hundreds of thousands of DOM nodes, assuming you aren't doing anything weird like blocking on layout in one of them.
Let's aim for frameworks that are in the ballpark of peak raw performance, before we look to parallelism and multi-threading as a solution.
That someone possibly had the mistaken belief that this was peak performance for a hand-rolled WebGL codebase shows how low and out-of-touch our expectations for performance really are.
I totally agree on this.
> assuming you aren't doing anything weird like blocking on layout in one of them.
An assumption that react cannot make.
React's core promise is to make app developers lives easy, not to be performant. Performance is atrocious on the web in general, yet here it is as (one of?) the most dominant app development platforms.
With that easiness what you get is plenty of horrible (from a performance perspective) applications that get their jobs done. Some even very elegantly on many other metrics.
> Let's aim for frameworks that are in the ballpark of peak raw performance
That is a nice aim, but performance can be traded for other things. Immutable data structures will never be as performant as mutable ones, yet plenty of people make the conscious decision of using the former.
I see React's approach similary. I've built plenty of web applications in my life, and very rarely did (non-network) performance become a significant issue. As you said, computers are so powerful nowadays that most people (even devs!) cannot even comprehend it at an intuitive level.
It is always the app's logic, changing business requirements, etc. that bite me in the ass. I want tools that make that part easier. React is definitely one of those tools today. And if they found a way to keep the easiness while being better performance-wise then... yay!
Yeah, and still a good number of electrons apps arrive to put my CPU at 100% for something as advance as "text editing".
CPU are powerful when used right.
No one thought that though. This is a demo of good performance using a web framework on top of a WebGL framework. It's showing that a future version of React will make building a solid 60fps web app UI is within the reach of most web developers. Sure, you can hand-roll code to get that performance today if you know how, but this is about putting that performance in the hands of developers who can't (or, more often, aren't given the resources to). To argue that is unnecessary or actually bad is ridiculous. Libraries that make it easier to build better apps are universally good things.
> I'm pretty sure it will run circles around even the best performing manual three or webGL apps out there soon.
Last I tried that was back in 2013. Haven't tried that particular benchmark since, but have tried others, and I don't believe things have changed much to move that particular needle.
The benchmark was updating the translate3d(random, random, 1px) of multiple 20x20 divs with a black background. It would increase the number of divs until we'd start to have dropped frames.
Obviously no re-layout, no repaint, practically no time spent on the script, and no GC. Compositor only.
Chrome on Windows on a beefed up PC maxed out at around 400 squares (divs).
So no, hundreds of thousands of divs would not be possible. Not on Blink's architecture at least. WebRender is trying to change that, but it's still too early to tell.
I tried the same benchmark with hand-written WebGL, and made sure that the black squares are drawn one-by-one to simulate how Chrome did it (no batched draw calls).
That maxed out at around 1k squares. Obviously all that time was being wasted back-and-forthing between the script and the GPU.
Then tried batching the draw calls (square coords on a large typed array), and that got me to, iirc, millions.
> That someone possibly had the mistaken belief that this was peak performance for a hand-rolled WebGL codebase shows how low and out-of-touch our expectations for performance really are.
True. It is mathematically impossible for react to beat hand-optimized WebGL. I'd guess it won't come close to 1/100 of the raw throughput. It would require a different programming model. And then it would no longer be React.
Two things produce conviction in people regarding technical matters: ignorance and experience. You clearly have the experience.
Tech needs more people like you.
Here's a dead simple demo in pure vanilla JavaScript: https://brianbeck.com/particles.html
Go ahead and see what number you get to before it drops below 60fps. Personally I have to decrease it to 1000 or so on my 2018 MacBook Pro.
And that's updating a style property that does not cause reflow calculation.
Anyone including Jasper_ is welcome to post a similar demo of their 100x+ performance improvements on this, but I doubt they will.
(See Jasper’s later comment that the described scenario was in fact a very specific example that probably doesn’t extend to many very common simple DOM manipulations and might have relied on a browser-specific optimization that no longer exists.)
Very cool website! I just noticed you're the one behind it[1]! Just curious: when people contribute textures toy our project, do they have to get permission from the video game publisher first?
Also, how hard is the process of extracting the textures of a video game? Is there effort involved in stitching multiple DDS/other texture files together, so that it can presentable on your website?
In the case of the Galaxy levels, it's reading the raw files as shipped on the Wii disc. I have my own renderer and emulation tech [0]. It's the only way to ensure accuracy to a degree I'm happy with. For textures specifically, they're stored in the Wii's texture formats, so I have my own texture decoder [1].
I did not get permission from the original game developers, but I think I'm doing everything here in good faith, out of love for the source material, and that I'm not replacing the experience of playing the game for yourself. The developers of Fez specifically retweeted a post about it on the official Twitter.
[0] https://github.com/magcius/noclip.website/blob/master/src/gx... [1] https://github.com/magcius/noclip.website/blob/master/src/as...