New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encoding: use Wasm to get a SharedArrayBuffer instance #22361
Conversation
encoding/encodeInto.any.js
Outdated
return new ArrayBuffer(length); | ||
} else { | ||
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` | ||
// WebAssembly.Memory's size is in multiples of 64 KiB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we actually create a 64 KiB buffer here?
Could we instead grab a copy of buffer
's constructor and use that to construct a SharedArrayBuffer instance of the exact size specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
9774d70
to
86d52aa
Compare
86d52aa
to
0dff2c4
Compare
encoding/streams/decode-utf8.any.js
Outdated
|
||
const emptyChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](0)); | ||
const inputChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](inputChunkData.length)); | ||
function createBuffer(type, length = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be inside the loop?
Non-owner lgtm. |
@ricea I think you should feel free to call yourself an owner of this directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with potential improvements.
encoding/encodeInto.any.js
Outdated
@@ -1,3 +1,13 @@ | |||
function createBuffer(type, length = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worth pulling this out into /common
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking to maybe do that, okay. And then use some closure to only do the WebAssembly thing once and hide the constructor. /common/sab.js
okay? I'll prolly clean up these 4 PRs with that tomorrow then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
encoding/encodeInto.any.js
Outdated
function createBuffer(type, length = 0) { | ||
if (type === "ArrayBuffer") { | ||
return new ArrayBuffer(length); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a test, IMO it's worth doing an explicit test that type === "SharedArrayBuffer", and throwing an exception if it's neither of the two. (A switch/case would also work.)
I created sab.js. I guess it would be good for this to land first and then we see if we want to use it in the other PRs. (Edit: they don't need it. They are just creating a single instance and I don't really want to complicate them all by loading another file.) |
For #22358.