W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2011

Re: What changes to Web Messaging spec are proposed? [Was: Re: Using ArrayBuffer as payload for binary data to/from Web Workers]

From: Dmitry Lomov <dslomov@chromium.org>
Date: Fri, 3 Jun 2011 14:29:11 -0700
Message-ID: <BANLkTi=tiTVy5m87zw0qgau+0+vSxiu=Gg@mail.gmail.com>
To: Andrew Wilson <atwilson@google.com>
Cc: Jonas Sicking <jonas@sicking.cc>, Kenneth Russell <kbr@google.com>, Glenn Maynard <glenn@zewt.org>, David Levin <levin@chromium.org>, ben turner <bent.mozilla@gmail.com>, "public-webapps@w3.org" <public-webapps@w3.org>, Ian Hickson <ian@hixie.ch>, Travis Leithead <Travis.Leithead@microsoft.com>
On Fri, Jun 3, 2011 at 2:15 PM, Andrew Wilson <atwilson@google.com> wrote:

>
>
> On Fri, Jun 3, 2011 at 1:02 PM, Jonas Sicking <jonas@sicking.cc> wrote:
>
>> On Fri, Jun 3, 2011 at 11:37 AM, Kenneth Russell <kbr@google.com> wrote:
>> > On Fri, Jun 3, 2011 at 9:46 AM, Glenn Maynard <glenn@zewt.org> wrote:
>> >> On Fri, Jun 3, 2011 at 11:12 AM, Dmitry Lomov <dslomov@google.com>
>> wrote:
>> >>> a) Recursive transfer lists. Allow arbitrary objects, not only
>> ArrayBuffers,
>> >>> to appear in transfer lists.  ArrayBuffers that are under objects in
>> >>> transfer lists are transferred, others are cloned.
>> >>
>> >> This again causes the same forwards-compatibility problem.  If you do
>> this:
>> >>
>> >> frame = { video: canvasPixelArrayInstance, histogram: arrayBuffer } }
>> >> postMessage({ frame: frame }, { transfer: frame });
>> >>
>> >> and you expect only histogram to be transferred (since that's all that
>> >> supports it when you write this code), your code breaks when
>> >> CanvasPixelArray later supports it.
>>
>
Right, but you should not write { transfer : frame }, you should write:
postMessage( { frame: frame }, { transfer: frame.histogram })

in this case. The guidance for transferring objects should be: do not
transfer objects you intend to use on this "thread" (on main thread, worker)
- only transfer parts that you do not intend to use. This version of
postMessage gives a high-fidelity tool for you to do so if desired, but
handles the opaque case as well.


> >>
>> >>> b) Transfer lists + separate transferMessage method. We still equip
>> >>> postMessage with transfer lists, these transfer lists list
>> ArrayBuffers, and
>> >>> we provide a separate method transferMessage with recursive transfer
>> >>> semantics.
>> >>> What do people think?
>> >>
>> >> Same problem.
>> >>
>> >> If you want a quicker way to transfer all messages of given types, see
>> >> my previous mail: { transfer: ArrayBuffer }.
>>
>
(sorry I somehow missed your previous mail when replying)
I do not think filtering by types solve much.

Consider again a case of two library functions compute() returning some data
and present(data) rendering some data, where library user treats the data as
a black box. In first version, library author used ArrayBuffers as part of
data internally, because it is the only data type that is transferrable.
Now, CanvasPixelArray became transferrable as well, and library author
changes the library to compute those as part of the data, to offload more of
the computation to "compute" phase. With filtering by types, all library
user will need to modify their code as well, to add CanvasPixelArray to a
list of transferrable types in their postMessages.

Again, I think having a transfer list (as some argument to postMessage) is
great solution for high-fidelity control. Low-fidelity, opaque, "don't show
me the implementation" use cases is what is missing.


> >
>> > Agreed on these points. Using an object graph for the transfer list
>> > (which is what the recursive transfer list idea boils down to) also
>> > sounds overly complicated.
>>
>
It feels that but not solving this as part of messaging spec we just offload
the complexity to the users.


> >
>> > May I suggest to reconsider adding another optional array argument to
>> > postMessage for the transfer list, rather than using an object with
>> > special properties?
>> >
>> > Points in favor of adding another optional array argument:
>> >
>> > 1. Less typing, and less possibility that a typo will cause incorrect
>> behavior:
>> >  worker.postMessage(objectGraph, null, [ arrayBuffer1ToTransfer,
>> > arrayBuffer2ToTransfer ]);
>> >    vs.
>> >  worker.postMessage(objectGraph, { transfer: [
>> > arrayBuffer1ToTransfer, arrayBuffer2ToTransfer] });
>> >
>> > 2. Possibility of using Web IDL to specify the type of the optional
>> > array argument (i.e., "Transferable[]?"). Would be harder to do using
>> > an object -- requiring either specifying another interface type with
>> > the "ports" and "transfer" attributes, or using "any" plus
>> > ECMAScript-specific text.
>> >
>> > Points in favor of using an object:
>> >
>> > 1. Could potentially overload the meaning of the optional ports array
>> > argument, avoiding adding another argument to postMessage.
>> >
>> > 2. More extensible in the future.
>> >
>> > Thoughts?
>>
>> My first thought is that so far no implementer has stepped up and said
>> that changing the meaning of the 'ports' argument would not be
>> acceptable. Would be great if someone who is reading this thread and
>> who works at Google/Apple/Opera could check with the relevant people
>> to see if such a change would be possible.
>>
>
> It's certainly possible - there's nothing intrinsically difficult with
> making this change from an implementor's point of view (I've had my fingers
> in both the WebKit and Chromium MessagePort implementations so I'm
> relatively confident that this would not be prohibitively hard).
>
> Is it desirable? My knee-jerk reaction is that we should stick with changes
> that are compatible with the existing API (like Ian's original suggestion,
> or adding a separate optional array of transferable objects) - I have no
> data on the number of sites that are using the current API but I don't think
> we should be changing existing APIs with multiple implementations without
> significant motivation. The stated motivations for breaking this API don't
> seem compelling to me given the existence of backwards-compatible
> alternatives.
>
>
>
>>
>> / Jonas
>>
>>
>
Received on Friday, 3 June 2011 21:29:39 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:45 GMT