Encoding: use Wasm to get a SharedArrayBuffer instance #22361
Conversation
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 |
ricea
Mar 23, 2020
•
Contributor
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?
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?
annevk
Mar 23, 2020
Author
Member
Done.
Done.
|
||
const emptyChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](0)); | ||
const inputChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](inputChunkData.length)); | ||
function createBuffer(type, length = 0) { |
ricea
Mar 23, 2020
Contributor
Does this need to be inside the loop?
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. |
LGTM with potential improvements. |
@@ -1,3 +1,13 @@ | |||
function createBuffer(type, length = 0) { |
domenic
Mar 23, 2020
Member
It may be worth pulling this out into /common
It may be worth pulling this out into /common
annevk
Mar 23, 2020
Author
Member
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.
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.
domenic
Mar 23, 2020
Member
SGTM
SGTM
function createBuffer(type, length = 0) { | ||
if (type === "ArrayBuffer") { | ||
return new ArrayBuffer(length); | ||
} else { |
domenic
Mar 23, 2020
Member
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.)
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.) |
4e83bff
into
master
For #22358.