Hi, I’m developing a project using svelte.js, typescript, and rollup, and I was wondering if the offscreen canvas feature is compatible. The issue I’m facing currently is that I can’t access my source code from the worker.js file; I am trying to instantiate a copy of the scene that I am rendering on the main thread, but I can’t access the code to do so. I have tried serving the app with an https connection with vercel, and I managed to get the source code to show up in the worker thread, but I still cannot access it in worker.js (When I say “show up in the worker thread”, I mean that in the sources section in the dev tools it shows that the source files are under the worker.js folder as well as on the main thread folder; I did this by using importScripts("[linkTobundle.js]")). However, I’m still unable to access the classes and functions of the main thread. Is there something else I should be importing with importScripts or with import to allow the worker.js file to have access to the source files?
The only way to communicate back and forth worker and main thread is through messaging. I would advise to not try to run all the code this way for perf reasons and encapsulate higher level functions behind dedicated messages. Then it might be easier for you to emit the correct messages and listen for them from worker to main thread ?
It is not the amount of code, it is the frequency and type of data you are sharing across the threads which are important here.
For instance if you share json it will be copied across the thread costing lot of perfs if you do it for every vectors/matrices in your app. On the opposite if you use shared array buffer it should be way cheaper.
This is really the app responsibility to be mindfull about the frequency and content of data shared accross the threads but it needs to be kept in mind to prevent harming more than helping.
Understood. Thank you @sebavan