Skip to content

Chrome vs spec: encoder.encodeQueueSize #494

@chcunningham

Description

@chcunningham

Chrome's implementation of encoder.encodeQueueSize (and decoder counterpart) doesn't match the spec. The difference is fairly minor, but I think authors will prefer Chrome's behavior. It ends up being a bit of yak shave...

Background

The spec/impl mismatch stems from Chrome's impl of the codec processing model.

The spec defines a control message queue with messages enqueued on the control thread and dequeued on the codec thread. In Chrome's implementation both enqueuing and dequeuing actually happen on the control thread. We use a separate mechanism ("post task") to communicate with the codec thread (where encoding actually happens). This is effectively also a queue, but it's distinct from the control message queue. For the spec, combining control-signal-queuing and thread-message-passing seemed like a nice simplification with no difference in observable behavior... almost.

The issue arises with when to decrement encodeQueueSize.

Per spec, it takes at least one turn of the event loop to learn that your encode() has been processed, even in cases where the encoder wasn't saturated and could accommodate the request right away. This is a consequence of the dequeue happening on the codec thread and posting a task to update the counter.

In Chrome's impl, authors may instead observe cases where encode() was immediately processed without waiting a turn of the event loop. In such cases the control message is dequeued before encode() even returns and we don't increment the encodeQueueSize counter.

Proposing a spec change

The purpose of the encodeQueueSize attribute is to give authors a way of monitoring back pressure from the underlying codec. Incrementing for every encode() and decrementing sometime later adds unpleasant indirection.

Having the spec match Chrome requires updating the "Codec Processing Model" to process the queue entirely on the main thread. This is a big editorial change, but the only author-observable difference would be for encodeQueueSize. Finding this bug has made me nervous that the current Codec Processing Model elides too much. Making it match the impl more closely seems prudent.

Please see a preview of the spec change in #493.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions