-
Hello! First of all, let me thank you for the wonderful framework, it's been truly a bliss to get started with it. I have stubbed some CPU-intensive piece of calculation, trying to ensure that it is not getting optimized out (iterating over 1..n checking 3n+1 hypothesis), and build very simple UI with a button to trigger it. When I do it on desktop build I get around 3.5 seconds of execution time - that would be a baseline. On web for the same code I get around 9s on first execution and then it drops under 4s on further ones -- I guess some optimizations are kicking in on the fly - couldn't find any information if Chrome does any JIT-like optimizations for WASM code. I was wondering whether there might be some additional guidelines in order to achieve same performance in workers as when using browser's event loop, or whether something in current implementation of tokio-with-wasm may be preventing them from happening. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To answer my own question (and, hopefully, save someone from spending couple of evenings debugging the issue), there were two separate reasons for slowdown, which I was triggering occasionally, and, ironically, my attempts to add more logging or do profiling made situation worse. TL;DR: Opening dev tools degrades WASM performance; running loop in a function instead of spawn/spawn_blocking it on each call degrades performance if function ends up called only once. |
Beta Was this translation helpful? Give feedback.
To answer my own question (and, hopefully, save someone from spending couple of evenings debugging the issue), there were two separate reasons for slowdown, which I was triggering occasionally, and, ironically, my attempts to add more logging or do profiling made situation worse.
Reason 1: Opening dev tools. Expected behaviour, however, as per V8 docs. Googling for "Chrome wasm JIT" was not very efficient, so it took me some time to catch this one, and "profiling" section is what made it even more fun, as during profiling all code suddenly got tiered up, eliminating the issue.
Reason 2: While trying to fix the issue, I switched to having single worker in a loop waiting for message in chan…