react-native-threads icon indicating copy to clipboard operation
react-native-threads copied to clipboard

Worker thread has much slower performance

Open mfbx9da4 opened this issue 3 years ago • 4 comments

I'm using this library to do some JS blocking file decryption on a worker process. This library works great to free up the main thread but the actual decryption time seems to be about 10x slower than doing the same decryption on the main JS process. Is the worker process somehow resource constrained? Why might this be?

Tested on iOS 15 in the simulator.

mfbx9da4 avatar Jan 20 '22 12:01 mfbx9da4

You've got the cost to start up a new JS VM, parse the additional source code (+ parse the RN source code again), send the contents from your main JS process to the new one, and send it back.

Can you not use native code to do the decryption?

jacobp100 avatar Apr 04 '22 16:04 jacobp100

Yep that's what I went with

mfbx9da4 avatar Apr 04 '22 17:04 mfbx9da4

Is there a one off cost to constructing the new JS VM? ie is the worker re-used for subsequent calls?

mfbx9da4 avatar Apr 04 '22 17:04 mfbx9da4

Yeah, the worker is created every time you do new Thread. Then any postMessage calls re-use it. It only gets removed if you explicitly call thread.terminate(). The cost is pretty huge to create the worker though (enough to justify Facebook building the Hermes JS engine)

jacobp100 avatar Apr 04 '22 17:04 jacobp100