Hacker News new | past | comments | ask | show | jobs | submit login

I love Node - does anyone have good experiences with using Node with Rust/Java/C++ for interop as necessary performance wise?

I know it's possible and that some teams do it, but the story wasn't great with (much) earlier versions of node. Some teams just wrote their stuff in another language and just use a child process in node to call it, serializing everything as a string and DE serializing it in the other language. The problem with that though is that you suffer a pretty decent performance penalty serializing and deserializing, and though it still might be worth it, it's also not great since some teams actually just called similarly to how you'd call a shell script.

Is it much better than that now?




Node has always supported native addons, and since 2017 it also provides a stable ABI making the process a whole lot easier[1].

That said, in my own experience it was seldom worth it to rewrite something in C++ for performance sake. After rewriting some computationally heavy part as a native addon, I often ended up gaing only ~20% more perfomance at best when compared to properly optimized JS implementation, and even that was not guaranteed since V8 improved rapidly. That was not a good enough reason to keep a whole different tool chain around, so I'd end up going back to JS.

[1] https://medium.com/netscape/javascript-c-modern-ways-to-use-...


What about with wasm? I assume there's a good interop story there like there is in the browser, and you don't have to worry about building for different platforms


WASM has its moments, as you can see in this[1] benchmark it outperforms JS and native addons on certain tasks.

Since the bottleneck with native addons is usually data copying/marshalling, and we have direct access to WebAssembly memory from the JavaScript side, using WebAssembly on this "shared" memory might become the best approach for computationally heavy tasks. I wrote about it a bit here[2].

[1] https://github.com/zandaqo/iswasmfast

[2] https://medium.com/swlh/structurae-1-0-graphs-strings-and-we...


Yup wasm is the way to go as you can just distribute the wasm binary over npm and don't have to worry about further compile steps on the consumer side, but it's not always possible to use wasm.


I have written a native C++ module to speed up JSON parsing and manipulation by a factor of 10x+


Sell it to Rockstar. Their native C++ JSON parsing seems to be 10x slower than JS/Node.


If you want to interface with Node from Rust there's a great library called Neon[0] that wraps the C/C++ Node addon api.

[0] https://github.com/neon-bindings/neon




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: