Fork me on GitHub
#re-frame
<
2022-06-01
>
Jérémie Salvucci13:06:20

Hi, when we use an event handler to actually perform a heavy task (serializing a whole 3d scene + uploading it to a server), there is a risk of cpu hog and the interface might be unresponsive for some time. But I noticed that in some browsers (Metamask for instance) the interface might get unresponsive forever. Is it an expected behavior? Is there a pattern to perform this kind of task (setTimeout or something different) ? Another solution would be to actually split the file to upload in several chunks and send each one separately to have a better interaction with reframe pipeline.

p-himik16:06:47

It's not expected - my knee-jerk reaction would be to blame the browser (I've had enough instance where it was the case). For all expected CPU hogs, there are some solutions here: https://day8.github.io/re-frame/Solve-the-CPU-hog-problem/

p-himik16:06:32

Another potential solution is to use a web worker. But it doesn't work in all cases, so you gotta reason about it and maybe try and measure.

Jérémie Salvucci18:06:13

I blamed the browser too (especially because it only happens with this one (Metamask)). Ok, I'm going to think about a way to circumvent the issue. Thank you!

👍 1
superstructor23:06:45

In some cases of CPU-hungry code, it may be worth considering web workers e.g. https://github.com/jtkDvlp/re-frame-worker-fx I havn't used that fx myself but the impl looks reasonable. There are some obvious caveats, such as you need to serialize the input to the web worker to be able to send it to the web worker - so for an issue like serializing a large 3d scene it may not help you at all since you'll need to serialize it to pass it to the web worker. But it is worth keeping in mind as an escape hatch from the main single UI thread in some circumstances.

sansarip14:06:15

Another path to consider is that of web assembly 🧙