Web-Worker with huge message

140 views Asked by At

I'm currently facing a throttle with web-worker.

Here is what I'm trying to do:

  1. Main thread: sends a request to web-worker
  2. Web-worker: forward this request to a web service. The web service answers with ~1MiB of data
  3. Web-worker: post processing the data from the web service, expanding the payload to ~4MiB
  4. Web-worker: sends the 4MiB payload to Main thread
  5. Main thread: Receives the message, deserialize it (the time consuming part). Accessing MessageEvent.data is the bottleneck of the whole message reception handling.
  6. 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.

0

There are 0 answers