I have a worker in development that uses web assembly (compiled from rust).
To avoid excess CPU, I tried using a global variable to reuse a struct setup in a preview request. The worker now fails with “script exceeded time limit”.
The struct should be extremely small (in theory, I know wasm can in inefficient with memory) so this is very surprising.
There’s a PR showing the change at Switch to JSX parsing using typescript by samuelcolvin · Pull Request #1 · samuelcolvin/edgerender · GitHub
Can anyone explain this or point me to how to fix this?
Feel free to reply here or on github.
Update: I’m guessing this is because the ENV
object in javascript only stores a pointer to the object in webassembly, although that js object is stored and available on the second request, the associated struct in webassembly has been destroyed. So accessing the env the second time causes the equivalent of a segfault and the worker crashes with the above error.
Is that correct? If so is there any way to tell prevent the wasm struct from being destroyed between requests?
Update 2: I see the error is happening on await wasm_bindgen(wasm)
, not when accessing ENV
.