Standard hash performance on WASM

I noticed that hash maps with integer keys are really slow on WASM. So I used IntMap from nohash_hasher crate and it solved the issue for me.

But now I had to use u128 as a key, and it was not possible to directly use nohash_hasher with them, because hashes are u64 in rust. I had to write some actual code to use similar approach for u128, and I had to make some tests to see if it worked.

Here are the results on my machine:

So, for native target xor hash is ~4 times faster than default hash.

In Chrome default hash is ~20 times (!) slower than native, while xor hash is only ~5 times slower than native. Also, in chrome xor hash is ~15 times (!) faster than default hash.

In Firefox default hash performs roughly the same as in firefox, while xor hash is ~30 times slower than native and ~6 times slower than in Chrome.

I've added "sum indices" test to check general performance not bound to hashes. In chrome this test runs at basically the same speed as native and in Firefox it is ~10 times slower.

So, here are my questions:

  1. What's wrong with hashes on WASM? Even xor hash is 5 time slower, while general code runs at basically the same performance in chrome.
  2. What's wrong with performance in Firefox? I see some reports that it should be the same or even faster than Chrome.

Can it be that I configured the project wrong?

As for Firefox performance the answer is simple: run the program without the devtools opened and the performance is on par or even better than chrome.

If you have the devtools opened when the wasm module gets compiled, it will compile it in debug mode to allow setting breakpoints. For javascript spidermonkey will deoptimize the target function on the fly when actually setting a breakpoint, but for wasm deoptimization or is not supported so it has to run in debug mode from the start. By the way in the past debug mode would consume a lot of memory for large wasm modules, but it seems like they fixed that now.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.