[Workers] Document streams_byob_reader_detaches_buffer compatibility flag#2644
Merged
kentonv merged 5 commits intoDec 1, 2021
Merged
Conversation
…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.
kentonv
reviewed
Nov 22, 2021
|
|
||
| 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. |
Member
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
I added a little example.
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. :( |
a3d1b4b to
67b5c61
Compare
67b5c61 to
e9f0839
Compare
kentonv
approved these changes
Nov 29, 2021
Member
|
LGTM but I guess my approval is not good enough as I'm not an owner. |
jasnell
approved these changes
Nov 29, 2021
deadlypants1973
approved these changes
Nov 30, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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