Skip to content
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

Merged
merged 4 commits into from Mar 24, 2020

Conversation

annevk
Copy link
Member

@annevk annevk commented Mar 20, 2020

For #22358.

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
Copy link
Contributor

@ricea ricea Mar 23, 2020

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's cunning. Yeah, I think that would work.

cc @syg @domenic

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@wpt-pr-bot wpt-pr-bot temporarily deployed to wpt-preview-22361 March 23, 2020 09:14 Inactive

const emptyChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](0));
const inputChunk = new Uint8Array(new self[arrayBufferOrSharedArrayBuffer](inputChunkData.length));
function createBuffer(type, length = 0) {
Copy link
Contributor

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?

@wpt-pr-bot wpt-pr-bot temporarily deployed to wpt-preview-22361 March 23, 2020 09:40 Inactive
@ricea
Copy link
Contributor

ricea commented Mar 23, 2020

Non-owner lgtm.

@annevk
Copy link
Member Author

annevk commented Mar 23, 2020

@ricea I think you should feel free to call yourself an owner of this directory.

Copy link
Member

@domenic domenic left a 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.

@@ -1,3 +1,13 @@
function createBuffer(type, length = 0) {
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

function createBuffer(type, length = 0) {
if (type === "ArrayBuffer") {
return new ArrayBuffer(length);
} else {
Copy link
Member

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.)

@annevk
Copy link
Member Author

annevk commented Mar 24, 2020

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.)

@annevk annevk merged commit 4e83bff into master Mar 24, 2020
@annevk annevk deleted the annevk/encoding-wasm-sab branch March 24, 2020 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants