News for hackers. Stuff that matters.
Re:Replacing JavaScript Hot Path with WebAssembly by seanwilson on Thursday February 14, 2019 @06:43PM (#19167180)
Maybe this is what you meant but the snippet can be optimised a ton as well unless I'm missing something:

- Move the "y * width" calculation outside of the "for x" loop.

- The multiply operators can be replaced with addition e.g. replace "y * width" with "counter += width" each y iteration and similarly for the x loop.

Optimising inner loops is really fun.

How much of the speed up in the article is because the JS engine can't figure out how to optimise it compared to the WebAssembly compiler?

Re:Replacing JavaScript Hot Path with WebAssembly by tom_mellior on Friday February 15, 2019 @04:03AM (#19169507)
These code motion/strength reduction optimizations are standard even in mildly optimizing compilers. I would be very surprised if an optimizing JavaScript compiler did not perform them automatically.
Re:Replacing JavaScript Hot Path with WebAssembly by robko on Thursday February 14, 2019 @07:21PM (#19167425)
I tried a few micro-optimizations, but they did not make a measurable difference, so I kept the code short instead. But maybe some JIT is particularly bad at loop hoisting, so it might make a difference there.