Interesting for maybe delegating JSON.parse to another language

55 views
Skip to first unread message

Ω Alisson

unread,
May 27, 2015, 7:50:30 AM5/27/15
to nod...@googlegroups.com

Matt

unread,
May 28, 2015, 8:44:03 PM5/28/15
to nod...@googlegroups.com
That's a naive way of looking at things.

JSON.parse is slower in Node not due to the parser itself, but due to constructing objects. So yes you could parse in C++, but your object access would be hundreds of times slower.

On Tue, May 26, 2015 at 7:11 PM, Ω Alisson <thelin...@gmail.com> wrote:

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CACZE8Y5TzyQp%2BYUmY5HFzHyCemh%3DS8-LkP%3DZ2yNRxxvxwO0zGQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Jimb Esser

unread,
May 28, 2015, 8:44:05 PM5/28/15
to nod...@googlegroups.com
In node/V8, from what I understand, JSON.parse is already delegated to another language, it's in (fairly) optimized C++ code.  What you're seeing in that benchmark (when comparing "C++" and "Javascript Node") is less the expense of parsing JSON and more the expense of creating heavy-weight, garbage collected, etc, Javascript objects, compared to much more light-weight native objects (which couldn't possibly be used by Javascript code, as they need to be wrapped in relatively expensive layers to be exposed).  If you look at an actual pure-Javascript JSON parser (e.g. json5), it's performance is going to be even worse =).

This does mean, however, if you're getting a bunch of JSON data, and distilling it into a relatively small amount of data, you may get a pretty significant speed-up by doing that in a native module (big JSON -> big native structure -> small JS structure instead of big JSON -> big JS structure -> small JS structure).  Of course, that's true of *any* data processing in node (or any interpreted language) - moving the CPU-intensive heavily lifting to optimized native code will give you a boost, it's just usually not worth the complexity of doing so.

On Wednesday, May 27, 2015 at 4:50:30 AM UTC-7, Alisson Cavalcante Agiani wrote:

Dave Horton

unread,
May 28, 2015, 8:44:35 PM5/28/15
to nod...@googlegroups.com
I had some luck using jansson (https://github.com/akheron/jansson) in my C/C++ program for parsing / formatting JSON.  Not sure why an alternative to JSON.parse is needed in a Javascript program though.

Ω Alisson

unread,
May 28, 2015, 11:58:01 PM5/28/15
to nod...@googlegroups.com
It's just that Node chokes with big JSON payloads and all async json parsers are cumbersome to use

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages