-
Notifications
You must be signed in to change notification settings - Fork 329
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
Fetch and SharedArrayBuffer #897
Comments
In general I think XHR is considered legacy and new capability should not be added to it, but the same question with regard to the fetch() API might make sense. |
Given that Fetch and XHR share some infrastructure it might end up affecting both, but let's discuss it in whatwg/fetch indeed. I've moved the issue. I guess the semantics here would be that the browser does a copy and not reads the bytes lazily? |
If the semantics are that the browser does a copy, you'll probably force it to make a copy, just to be sure that racing writes that would not be observable under a copy model are not in fact observed. What have we done elsewhere where we accept shared memory? |
I don't think there really is precedent within the web platform necessarily. What do other software platforms do? |
There is precedent now in https://encoding.spec.whatwg.org/#dom-textdecoder-decode. @domenic @wanderview @ricea @ddragana thoughts on adding Or would we instead require folks to do this through streams somehow? |
I haven't looked at what would be required in detail, but my first instinct is that allowing reading from a Reading into a async function toSharedArrayBuffer(response) {
const parts = [];
let totalLength = 0;
for await (const buffer of response.body) {
parts.push(buffer);
totalLength += buffer.byteLength;
}
const sab = new SharedArrayBuffer(totalLength);
const u8 = new Uint8Array(sab);
let offset = 0;
for (const buffer of parts) {
u8.set(buffer, offset);
offset += buffer.byteLength;
}
return sab;
} This is certainly long and fiddly enough that it would be useful to have a built-in. |
Multithreaded WebAssembly applications may wish to perform HTTP POST uploads from data that lives within their WebAssembly heaps. That is, they may execute
but that fails with an error
as a workaround, one can perform a deep copy of the data from a shared array view to an unshared array view with
This works, but having to do this potentially large deep intermediate copy of all data to upload can be costly.
Several other entry points of web apis have been expanded to allow SABs as inputs. Would it make sense for xhr.send() as well?
CC @lars-t-hansen
The text was updated successfully, but these errors were encountered: