News for hackers. Stuff that matters.
Re:Comparing Rust and JavaScript by hajile on Friday July 15, 2022 @10:02AM (#32108314)
Last I checked, destructuring created 4-5x as many bytecode instructions and a potential GC pause. I'd think this could be detected and optimized easily enough, but I guess there are bigger problems for the JIT devs to solve.

A quick profiling seemed to indicate that just a bit less than 10% of the JS time is being spent on the DOM rather than the calculations at hand. I wonder how much of that could be reclaimed simply by running the calculation in a web worker.

I suspect the bitwise AND operator every loop is another big performance issue. Normally, the JIT would leave the loop iterator as a 31-bit int, but because it is stored in a shared object, I suspect it must (f64 -> i31 -> AND -> f64) every time. A local variable that updates the object variable every 64ms and resets to zero would probably be faster.

The decPixel function should use a switch statement with values of 0, 1, 255, and default so it only needs to branch one time. This is probably a decent performance win too as around 15-20% of all time is spent here.

EDIT: I should praise the author for using a ternary instead of Math.max() as very few people know that the ternary is literally 100x faster. I wonder why this optimization was never made as it seems common enough.

Re:Comparing Rust and JavaScript by drawfloat on Friday July 15, 2022 @01:38PM (#32110768)
I actually thought Math.max was faster in modern Chrome than a ternary.
Re:Comparing Rust and JavaScript by hajile on Friday July 15, 2022 @05:12PM (#32112868)
You can try for yourself (this uses an if..else, but they compile to the same thing)

https://www.measurethat.net/Benchmarks/Show/6528/0/mathmin-v...