Skip to content

[Workers] Document streams_byob_reader_detaches_buffer compatibility flag#2644

Merged
kentonv merged 5 commits into
productionfrom
harris/add-streams-byob-reader-detaches-buffer-compatflag
Dec 1, 2021
Merged

[Workers] Document streams_byob_reader_detaches_buffer compatibility flag#2644
kentonv merged 5 commits into
productionfrom
harris/add-streams-byob-reader-detaches-buffer-compatflag

Conversation

@harrishancock

Copy link
Copy Markdown
Contributor

This compatibility flag is new as of this week.

Note that the text references a relatively new, non-standard method that we added to ReadableStream: readAtLeast(). Unfortunately, this method is not yet documented.

/cc @jasnell

…flag

This compatibility flag is new as of this week.

Note that the text references a relatively new, non-standard method that we added to ReadableStream: `readAtLeast()`. Unfortunately, this method is not yet documented.
@harrishancock harrishancock requested review from a team and kentonv November 5, 2021 12:39
@harrishancock harrishancock requested a review from a team as a code owner November 5, 2021 12:39
@haleycode haleycode added this to the Pages and Workers milestone Nov 5, 2021
Comment thread products/workers/src/content/platform/compatibility-dates.md Outdated
Comment thread products/workers/src/content/platform/compatibility-dates.md Outdated
Comment thread products/workers/src/content/platform/compatibility-dates.md Outdated

Originally, the Workers runtime did not detach the `ArrayBuffer`s from user-provided TypedArrays when using the [BYOB reader's `read()` method](/runtime-apis/streams/readablestreambyobreader#methods), as required by the Streams spec, meaning it was possible to inadvertently reuse the same buffer for multiple `read()` calls. This change brings us in line with the spec.

User code should never try to reuse an `ArrayBuffer` that has been passed into a [BYOB reader's `read()` method](/runtime-apis/streams/readablestreambyobreader#methods). The more recently added extension method `readAtLeast()` will always detach the `ArrayBuffer` and is unaffected by this feature flag setting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can reuse the buffer, just not under the same reference? That is, when read() returns, it gives you a new reference to the buffer, which you can then use in the next call. This seems like the whole point of BYOB, to avoid allocation overhead, so we should probably be a bit clearer here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a little example.

@kentonv

kentonv commented Nov 22, 2021

Copy link
Copy Markdown
Member

Sorry for failing to see this earlier, I have this repo muted because it was sending me too many notifications that weren't relevant to me... but that means I also missed a code review I was actually tagged on. :(

@harrishancock harrishancock force-pushed the harris/add-streams-byob-reader-detaches-buffer-compatflag branch from a3d1b4b to 67b5c61 Compare November 25, 2021 16:54
@harrishancock harrishancock force-pushed the harris/add-streams-byob-reader-detaches-buffer-compatflag branch from 67b5c61 to e9f0839 Compare November 25, 2021 16:55
@kentonv

kentonv commented Nov 29, 2021

Copy link
Copy Markdown
Member

LGTM but I guess my approval is not good enough as I'm not an owner.

Comment thread products/workers/src/content/platform/compatibility-dates.md Outdated
@kentonv kentonv merged commit d30cd80 into production Dec 1, 2021
@kentonv kentonv deleted the harris/add-streams-byob-reader-detaches-buffer-compatflag branch December 1, 2021 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants