-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
discuss: object serializer/deserializer + transferables #6300
Comments
Should this be pushed for in v8? Otherwise, is this an eventual candidate for the VM/API shim? Honestly, there isn't much point for this until workers land afaik. |
Cluster would benefit from faster serialization/deserialization. People complain it's slow to send large objects, thinking it's because it goes over a UNIX socket, but in my experience, it's the JSON.stringify/JSON.parse calls that are most expensive. |
Another potentialy related issue: #5453. |
|
@ChALkeR wouldn't (w/o searching the bottleneck) need to be a replacement but rather be an option. E.g. we could provide the option for shared memory IPC where this would be useful. @Fishrock123 looking at specs I doubt that we want to be a So from the discussion so far I conclude, that it would be interesting to at least look into it. If time allows I do so in the next couple of weeks. @bnoordhuis have you done any work on this so far? I know you have deferred this more then once in the past. |
We could make it opt-in by adding a new configuration option or a command line flag. That would make it semver-minor.
Nothing substantial. |
While I am for some kind of serializer that would allow to transfer more things than JSON.stringify (thinking about |
By default process.send() serializes messages using vanilla JSON.stringify(). This commit makes the serialization function configurable. Refs: nodejs#6300
V8-dev here: There work in progress to migrate the blink serializer to V8 see https://bugs.chromium.org/p/chromium/issues/detail?id=148757. |
Thanks for sharing. Might have missed it, but is there any other place a design discussion happened (on the internet)? |
@camillobruni ... out of curiosity, what is the newer format that is being looked at? Wouldn't be https://tools.ietf.org/html/rfc7049 by chance, would it? If so, +1. |
@jeremyroman is the implementor, he will know more details. From what I recall, its definitely not based on rfc7049 but rather an extension of the existing format. |
Hi, Blink dev here. My objective is to support the HTML structured clone algorithm for Blink, and for legacy reasons, we need to be able to read the format we already store on disk for IndexedDB. Even without the legacy constraint, the RFC7049 format doesn't seem to support some of the things HTML structured clone requires (e.g. reference equality is preserved, i.e., if a is an object, [a,a] deserializes such that a === a). Once that's done, I'll probably tweak the format to remove some legacy quirks and store some extra information to help speed up deserialization a little. I have a slightly out of date doc about that work. It's written from the perspective of Blink's needs. While I do expect it to substantially outperform Blink's current structured clone, there is some cost to tracking references (to handle circular structures etc.), so it may not outperform JSON.stringify. |
@jeremyroman Will it support regular expression, functions and streams? |
It will support RegExp, yes. Functions and streams are not structured clonable, so at present, no. I believe it's "no" to the others. (It's not even clear how a function would be cloned in general, given the existence of both "native" functions and functions which close over variables.) |
This has happened in #11048, closing 🎉 |
I wanted to propose this issue as a top-level home for discussions from multiple issues, amongst #2133, #3145.
Both issues are too big to have immediate action (judging from what I have read), but they have a serializer/deserializer feature in common,
node
,c++
andv8
are not providing out of the box. @bnoordhuis mentioned that it seems to be unrealistic to drag inBlink
code because of the many dependencies within that repo. I had a look also into theirWebWorker
implementation, which is fairly huge.Reading up on this from various c++ resources this is of course a non-trivial task. Whereas I also don't believe there will ever be a single method for arbitrary object serialization (please prove me wrong), due to the way v8 works. We would need to judge this before hand because that means a lot of serialization strategies would be insufficient for us.
As a quick guess, that would probably lead us to implement
::serialize()
methods per Class, no matter if binary or text, which would ensure serilization happens correctly at dev / build time.The text was updated successfully, but these errors were encountered: