Investigate passing to/from web workers
pastelmind opened this issue · comments
Yehyoung Kang commented
A task that parses a large PSD file can often exceed the 16ms budget in web browsers and block UI updates. To avoid this, it's natural to attempt parsing a PSD file in a Web Worker via postMessage()
and sending the results back. It would be nice to support this use case.
Unfortunately, this is currently impossible because the Psd
object cannot be reliably (de)serialized with the structured clone algorithm. Psd
provides instance methods and getters, which are lost when passed to/from a Web Worker.
We have some ideas, but would still like feedback:
- Convert the
Psd
class (and other classes) into plain, structured clone-able objects- Instance methods will have to be converted to plain functions
- This will be quite disruptive as it is backwards incompatible
- Create
Psd.prototype.serialize()
that generates a structured clone-able implementation, as well asPsd.deserialize()
that reconstructs the originalPsd
object- This will be clunky and leak implementation details all over