-
Notifications
You must be signed in to change notification settings - Fork 11
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
Can shared structs store SharedArrayBuffer? #16
Comments
It's a good point, and currently the answer is no. I haven't given it too much thought yet, but I agree we should do something here to be able to put SABs into shared structs. Do you think this is an important thing to have in the MVP? An aside on locks: the explainer is terribly out of date and I haven't had the cycles to update. The current plan is to directly provide a |
I'm not sure, being able to share chunks of binary data feels like it should be something that is supported. Like I could imagine something like having some image data on a shared struct that is replaced every frame. But I haven't personally hit any use cases that wouldn't be covered by the additional primitives. |
It would be valuable to add support for SharedArrayBuffer since one of the use cases would be to support parallel encryption which relies on bytes for keys and ciphertext. This would be valuable for any e2ee application (e.g. whatsapp web) |
I'd also say, that SharedArrayBuffer is highly beneficial. It solves many issues as such:
|
So in the current proposal, shared structs can only have fields that are themselves primitives or other shared structs.
However
SharedArrayBuffer
feels like it should be sharable and is kind've important to be able to share as it the only mechanism through whichAtomics
instructions other than the four available to shared structs would be available. Of particular note isAtomics.wait
andAtomics.notify
which are important for implementing locks and such.But currently
SharedArrayBuffer
probably couldn't be shared as it is an object, in fact the identity of theSharedArrayBuffer
in general doesn't round trip as a new wrapper object is created everytime it's cloned.Although having said that could we still set them anyway? There's a few possible strategies I could see:
SharedArrayBuffer
to be a shared struct so that it can be shared like any other shared structSharedArrayBuffer
would be a frozen object, so this might not be web compatiblesharedStruct.someBuffer
lazily creates aSharedArrayBuffer
object wrapper when accessedSharedArrayBuffer
const sabSharedRef = sab.toSharedArrayBufferRef()
/const sab = sharedStruct.sabRef.toSharedArrayBuffer()
The text was updated successfully, but these errors were encountered: