I'm currently facing a throttle with web-worker.
Here is what I'm trying to do:
- Main thread: sends a request to web-worker
- Web-worker: forward this request to a web service. The web service answers with ~1MiB of data
- Web-worker: post processing the data from the web service, expanding the payload to ~4MiB
- Web-worker: sends the 4MiB payload to Main thread
- Main thread: Receives the message, deserialize it (the time consuming part). Accessing
MessageEvent.data
is the bottleneck of the whole message reception handling. - Main thread: put the data into a Map
The thing is, deserializing the result message in the main thread is quite time consuming, i.e. between 20ms and 40ms.
Is there a way to share the initial object, as is, to avoid this serialization/deserialization that is not needed in my case ? It really seams that the usage of structuredClone
is what is the real problem in my application, as calling the field MessageEvent.data
is the bottleneck of the whole message reception handling.
The web worker is truly interesting to process large amount of data and long Rest requests, but the method of communication between threads is seriously putting me off.
EDIT: clarification on what does each thread.