--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
As far as I know, it's a fast cast-like thing. Here's a partial trace:
http://github.com/ry/node/blob/e97a481785dc5920336f46c7b29c6d9ff5fe974b/deps/v8/src/api.cc#L1775-1789
http://github.com/ry/node/blob/e97a481785dc5920336f46c7b29c6d9ff5fe974b/deps/v8/src/execution.cc#L446-449
http://github.com/ry/node/blob/e97a481785dc5920336f46c7b29c6d9ff5fe974b/deps/v8/src/runtime.js#L527-535
Can you expand on the cost of v8obj->ToObject(), Ryan?
On Tue, May 25, 2010 at 5:21 PM, Peter Griess <p...@std.in> wrote:Can you expand on the cost of v8obj->ToObject(), Ryan?Not really :) -- wasn't sure if it was a cast or a coerce situation (which is why I asked).I was just postulating based on my own limited knowledge of the APIs. What I'm curious about is the "when doing actual work" part -- meaning serializing... then _marshaling_, then deserializing (not just serializing and then deserializing in place as I can't think of why one would do that in the real world).So you have an object foo, assumed to be of moderate size and complexity (nested objects but no circular references, which is another issue of course). Then you pack it up via "var foo_pack = msgpack.pack(foo);". So now it's a Buffer, right? But it's a "packed" Buffer, not necessarily something usable in places expecting a Buffer unless they expressly expect a "packed" Buffer and are ready to deserialize properly (I suppose that relegates the usefulness to local code or external code under your control). OK, so in talking through this I think I see the use case you're after. You just want to avoid using strings locally as an intermediate format when all you need is a Buffer, and when you control the serialization/deserialization mechanisms at both ends. It's not necessarily a replacement for the cases when you're actually marshaling data to an external endpoint, at least not generically.
OK, so then you have circular references to deal with. I see your comments warn against a possible stack overflow for deeply nested objects, so that says circular references aren't accounted for either. I know one answer is "circular references are bad, don't use them", but there are handfuls of valid cases for them, and a good serialization mechanism should have a way to deal with them. Well, rather, once again... a "generic" serialization mechanism, right?Sorry, sort of free flow banter here. I get it now I think :) -- am I over-engineering this?
What I'm after is increased performance when transmitting a given JavaScript object over the wire. We have an advantage with node-msgpack both CPU usage and space usage for transmission/storage.
FWIW the MessagePack wire format is documented and has implementations in several other languages. It's certainly a format that one could use when communicating with external endpoints, as long as the transport had a mechanism for expressing the content encoding correctly (MessagePack vs. plaintext JSON).
OK, so then you have circular references to deal with. I see your comments warn against a possible stack overflow for deeply nested objects, so that says circular references aren't accounted for either. I know one answer is "circular references are bad, don't use them", but there are handfuls of valid cases for them, and a good serialization mechanism should have a way to deal with them. Well, rather, once again... a "generic" serialization mechanism, right?Sorry, sort of free flow banter here. I get it now I think :) -- am I over-engineering this?
Ooh, yeah I'm glad you brought up circular references.
I'll be rejecting any object with circular references as invalid for serialization, failing the entire operation. The MessagePack format (and JSON as well, for that matter) has no facility to support this.
This is what the built-in JSON.stringify() does:node> o['c'] = o;
{ a: 13, b: 14, c: [Circular] }
node> o
{ a: 13, b: 14, c: [Circular] }
node> JSON.stringify(o);
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at REPLServer.<anonymous> (eval at <anonymous> (repl:68:28))
at REPLServer.readline (repl:68:19)
at Stream.<anonymous> (repl:29:19)
at Stream.emit (events:25:26)
at IOWatcher.callback (net:507:14)
at node.js:204:9
--
You are using C++ for MessagePack. Perhaps because there is no
Buffer.pack() and Buffer.unpack() is very minimal?
I wrote http://github.com/nalply/node/commit/e2cf7839aafa3040577d385a9a05619ff39ab403
more than a month ago. Buffer.pack() and Buffer.unpack() with "d"
format. What do you think about a Javascript-only MessagePack for
Node.js if Buffer has pack() and unpack() with enough formats?
--nalply