Skip to content

Identity transform performance and ArrayBufferView ownership #323

@tyoshino

Description

@tyoshino

(based on @yutakahirano's analysis)

An identity transform can be designed to pass the ArrayBufferViews (after detaching) written to the writable side as-is to the readable side. This is good since no copy happens.

We have three choices in implementing this:

  • (a) on .write(), the transform takes ownership of the ArrayBufferView permanently
  • (b) on .write(), the transform takes ownership but returns it later (notify ownership release by fulfilling the promise returned by .write())
  • (c) on .write(), the transform reads out all the bytes from the ArrayBufferView. It never takes ownership.

(a) allows the transform to pass the ArrayBufferView as-is (after detaching) to the consumer through ReadableStream without ack capability (non-BYOB), but disallows the producer to reuse the buffer.

(b) allows the producer to reuse the buffer, but if the readable side is ReadableStream without ack capability (non-BYOB), there's no way to get the buffer returned by the consumer, so, we need to copy data inside the transform. To eliminate copy, we need ReadableStream with ack.

When BYOB reading is used, we anyway need to copy bytes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions