[html5] JSON parsing in Web Worker

Igor Minar iiminar at gmail.com
Tue Dec 28 10:35:11 PST 2010


I'm exploring the possibilities of using web workers for parsing large
JSON files outside of the main UI thread.

I found several references that this could be one of the use cases for
web workers (e.g. oreilly's intro to web workers [1]). However, the
more I read about webworkers, the less attractive they are for this
purpose, mainly because of how data is passed from worker to the main

Please correct me if I'm wrong, but my understanding is that any data
that is returned in the message from the worker, is copied rather than
shared and it seems that this is often implemented by serializing the
data into a json string and then deserializing it in the main script.
Is this right? Because if it is, then what's the point of parsing the
json string in worker thread, just to serialize it and then parse it
again in the main thread.

I'd love to be wrong about this because the concept of workers looks
like a perfect match for my use case (parsing large json payloads
quickly without affecting the UI), but my trivial microbenchmarks show
that the overhead of passing the data to, as well as from the
webworker is just too big to use it for this purpose.


[1] http://answers.oreilly.com/topic/1358-introducing-the-web-workers-api/

More information about the Help mailing list