[whatwg] asynchronous JSON.parse and sending large structured data between threads without compromising responsiveness
Ian Hickson
ian at hixie.ch
Wed Aug 7 14:21:17 PDT 2013
On Tue, 6 Aug 2013, Boris Zbarsky wrote:
> On 8/6/13 5:58 PM, Ian Hickson wrote:
> >
> > Parsing is easy to do on a separate worker, because it has no
> > dependencies -- you can do it all in isolation.
>
> Sadly, that may not be the [case].
>
> Actual JS implementations have various "thread-local" data that objects
> depend on (starting with interned property names), such that it's not
> actually possible to create an object on one thread and use it on
> another in many of them.
Yeah, the final step of parsing a JSON string might require sync access to
the target thread.
> > > For instance, how would you serialize something as simple as the
> > > following?
> > >
> > > {
> > > name: "The One",
> > > hp: 1000,
> > > achievements: ["achiever", "overachiever", "extreme overachiever"]
> > > // Length of the list is unpredictable
> > > }
> >
> > Why serialise it? If you want to post this across a MessagePort to a
> > worker, or back from a worker, why not just post it?
> >
> > var a = { ... }; // from above
> > port.postMessage(a);
>
> This in practice does some sort of serialization in UAs.
Indeed. My question was why do it manually.
> > why not just do this in C++?
>
> Let's start with "because writing C++ code without memory errors is
> harder than writing JS code without memory errors"?
>
> > I don't understand why you would constrain yourself to using Web APIs
> > in JavaScript to write a browser.
>
> Simplicity of implementation? Sandboxing of the code? Eating your own
> dogfood?
I guess that's a design choice.
But fundamentally, the needs of programmers writing Web browsers aren't
valid use cases for adding features to the Web platform. There's no need
for internal APIs to be interoperable.
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list