Skip to content

WIP DO NOT MERGE: Partial transferable support #59

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mlogan
Copy link

@mlogan mlogan commented Jul 17, 2015

See #58

Ok, here's where I've gotten so far:

  • TypedArrays and their buffers are serialized/deserialized properly, as in Chrome webworkers. (i.e. the thing that comes out on the other end is an identical typed array).
  • Transferables work in that new TypedArrays are constructed in the other thread from the same memory that was held in the previous thread. Arrays that are transferred become inaccessible in the thread they were sent from.

Still TODO:

  • I haven't tested this extensively, or put much effort into input validation in the postMessage API.
  • THIS CODE LEAKS BUFFERS: I've tried to use a Persistent handle with a weak callback to release the ArrayBuffer memory when the ArrayBuffer is GCed. Once you Externalize an ArrayBuffer as we do here, v8 will no longer free the backing memory at GC time. (See https://groups.google.com/forum/#!searchin/v8-users/ArrayBuffer/v8-users/CtOe7f6znZU/CDm-Rn0oJcMJ and https://groups.google.com/forum/#!searchin/v8-users/ArrayBuffer/v8-users/whHPAIhfMu8/D5H2-dP0HU4J for more info). However, I have no been able to get the callback to fire despite explicit calls to gc() with --expose_gc. I'm probably doing something wrong. I've gotten WeakCallbacks working before, so I'm somewhat at a loss as to why they aren't working here.
  • Additionally, even if we get the weak callbacks working, we need to relinquish our weak callback if the buffer is sent back to another thread. Otherwise double-deletes will result.
  • I haven't made much effort to use Nan for v8 API usage. Much of this code has no chance of compiling on v0.10 or earlier anyway, as that predates the ArrayBuffer/TypedArray C++ API in v8.

I'm probably not going to spend much time trying to resolve these issues, as I'm doing this for an embedded application in which we've already made some changes to the v8 ArrayBuffer API that will make the GC difficulties go away anyway.

That's no help to anybody wanting to use this code with an existing node install of course, for which reason this PR should not be merged. I'm posting it here in case anyone wants to take a crack at fixing the GC issues.

mlogan added 4 commits July 16, 2015 17:51
Serializes TypeArrays and their backing ArrayBuffers, and deserializes them
such that the resulting object is also a typed array. The deserialized array
is constructed with a backing ArrayBuffer of the same size and contents as the
serialized array, which is how typed array serialization works in Chrome/Blink
webworkers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant