News for hackers. Stuff that matters.
Re:Is WebAssembly magic performance pixie dust? by admax88q on Wednesday April 14, 2021 @01:00PM (#26809844)
JavaScript is fast. The browser is fast. But communication between the browser and javascript is really really slow.

They are written in languages with incompatible memory models, so lots of data must be copied when communication. They are running in different runtimes, so your javascript JIt can not inline function calls into the DOM.

That's why to this day, if you want to render a bunch of html from javascript, it is faster to generate a giant strin g of markup and pass that to the browser in a single 'innerHTML = "foo"' and let the browser parse all that, than it is to call a bunch of "createElement(); setAttribute(); appendChild();" calls.

Re:Is WebAssembly magic performance pixie dust? by zemnmez on Wednesday April 14, 2021 @01:05PM (#26809900)
I benchmarked this recently and I am pretty sure this is not true. Many of these 'single page site frameworks' work via this method.
Re:Is WebAssembly magic performance pixie dust? by admax88q on Wednesday April 14, 2021 @02:47PM (#26811321)
You are correct, I just did my own benchmark, and the DOM approach is no longer correct.

It used to be the case a number of years ago when I last benchmarked.

Re:Is WebAssembly magic performance pixie dust? by tiltrus on Wednesday April 14, 2021 @02:05PM (#26810769)
Can you share any benchmarks indicating this?
Re:Is WebAssembly magic performance pixie dust? by admax88q on Wednesday April 14, 2021 @02:47PM (#26811312)
I whipped up one here with a random comment dump from HN. It appears I'm no longer correct.

https://gist.github.com/adamvy/afcace8cbdbe56995626f59f6ea2b...

Load this as a script tag in an html file to run.

Last time I benchmarked this it was true, but that was a number of years ago.

Re:Is WebAssembly magic performance pixie dust? by admax88q on Wednesday April 14, 2021 @02:59PM (#26811484)
Actually, fun fact, if you remove the clearing of the body, the HTML approach is faster.

At least in firefox here.

Benchmarking is difficult.