News for hackers. Stuff that matters.
Re:Faster TypedArrays: Vector Addition in WebAssembly by brrrrrm on Sunday January 02, 2022 @03:23PM (#29773385)
It's definitely a bit faster with the unroll, but on my machine it's not by too much. I've added that idea to the interactive benchmark if you'd like to check it out!
Re:Faster TypedArrays: Vector Addition in WebAssembly by IvanK_net on Sunday January 02, 2022 @03:32PM (#29773508)
You probably implemented it in a wrong way. On my machine, a JSFiddle version is 3.5x faster, while in your benchmark, it is 1.4x faster.
Re:Faster TypedArrays: Vector Addition in WebAssembly by brrrrrm on Sunday January 02, 2022 @06:34PM (#29775336)
Your fiddle doesn’t seem to run a warmup or the code more than once. I’m guessing the second loop (the unrolled one) benefits from some JIT warmup.

That being said, I’m seeing a very similar relative difference in your fiddle to what I see in the benchmark I posted.

Re:Faster TypedArrays: Vector Addition in WebAssembly by eyelidlessness on Sunday January 02, 2022 @09:16PM (#29776563)
> JIT warmup

No kidding, this can be seriously misleading.

IMO JS (and likely many other JIT VM) benchmarks should run:

- multiple cold starts

- multiple pre-warmed starts (essentially run your bench twice, discard the results, run it again)

- isolated cases

- shared runtime cases with evenly distributed ordering

All of those will reveal different performance characteristics you may want to know about, and people evaluating your results should be able to know about. Cold starts are a worst case scenario of each implementation, warmed should show a more ideal outcome. Isolated will again highlight the perf of each implementation on its own merits, whereas shared runtime should help highlight how interacting with other real-world code affects VM optimization of that implementation.

Re:Faster TypedArrays: Vector Addition in WebAssembly by xpl on Sunday January 02, 2022 @11:35PM (#29777376)
Yeah, properly benchmarking JS code is hard because of how complex is the V8's optimizing compiler infrastructure. I once made an online tool for measuring run times of JS code, with [hopefully, lol] proper warmup and protection against possible dead code elimination optimization.

There are a few clickable benchmark examples in the readme: https://github.com/xpl/what-code-is-faster#what-code-is-fast...

Re:Faster TypedArrays: Vector Addition in WebAssembly by ignoramous on Monday January 03, 2022 @02:52AM (#29778374)
> No kidding, this can be seriously misleading.

Reminds me of prof. Emery Berger's talk, Performance Matters: https://www.youtube-nocookie.com/embed/r-TLSBdHe1A

Re:Faster TypedArrays: Vector Addition in WebAssembly by IvanK_net on Monday January 03, 2022 @04:38AM (#29778954)
If a 50-character piece of JS is running for two seconds, it was definitely optimized at some point. And even a most advanced optimization of 50 characters would not take more than 0.1 seconds.

Even with a warmup, the unwrapped version is more than 3x faster.

Re:Faster TypedArrays: Vector Addition in WebAssembly by brrrrrm on Monday January 03, 2022 @11:52AM (#29782804)
I fixed your fiddle to get the normal unrolled version 4x faster. Please see: https://jsfiddle.net/Lmzqpr03/

Largely, the use modern javascript and proper benchmarking made the results more consistent with the benchmark posted.

This included

1) avoiding the use of "var" (using let for scoped iterator variables and const for unchanging references)

2) using proper warmup (10% of runs)

3) isolating the benchmarked code into a function that can be invoked within a loop

4) reseting the values of the arrays being added between benchmarks (to prevent any NaNs/infinities from cropping up)

Re:Faster TypedArrays: Vector Addition in WebAssembly by IvanK_net on Monday January 03, 2022 @02:04PM (#29784829)
BTW. I replaced every "let" and "contst" with "var" in your code, and it seems to run about 15% faster: https://jsfiddle.net/05xd1oft/

Inserting the loop into a function really speeds it up in Chrome. Also, I have noticed, that for Float32Array, the rolled / unrolled performance is almost identical, but for Uint32Array, unrolled is about 30% faster: https://jsfiddle.net/aq06p94f/

Re:Faster TypedArrays: Vector Addition in WebAssembly by brrrrrm on Monday January 03, 2022 @06:07AM (#29779552)
Re:Faster TypedArrays: Vector Addition in WebAssembly by ShamelessC on Sunday January 02, 2022 @07:24PM (#29775756)
> You probably implemented it in a wrong way.

That's pretty opaquely rude, just FYI.

Re:Faster TypedArrays: Vector Addition in WebAssembly by tambourine_man on Sunday January 02, 2022 @06:07PM (#29775115)
Can you post a link to your version?