How to boost Node.js performance with C++ code

In Node.js, you can use C++ code to get higher performance. As Node.js is built up on top of C++, so you can leverage add-on to execute the c++ code. Recently, Inexplored it indepth for a usecase, where we needed nano or sub nano second latency on search across thousands of enteries. But apart from that, it gives you ability to directly work at low levels and use native APIs and drivers. To use C++ module, you can use N API or node-gyp. Have you tried it? #nodejs #javascript #backend #c

I know only one real use case for native C++ code in Node - something impossible to build in JS, like lmdb/mdbx. For most other scenarios e.g. JSONbig parsing switching JS/C++ context brings overhead erasing all the performance gain.

Like
Reply

Oh yes, i was on a project where you could upload a photo of your living room and try out new wallpapers on the walls in realtime. It was a nodejs backend with a wrapper for openCV in order to get the perspective correct transformation matrix ect. Super cool.

I'm just curious about performance. Even when you're writing c++ code you are using V8 datatypes and not core C++ datatypes. And for longer running projects compiling and managing these c++ code is very hectic. Also Many JS builtin functions we use are written in C++ under the hood, You can check the nodejs codebase for it. But yah if you have very small code which needs to written only once it might work.

See more comments

To view or add a comment, sign in

Explore content categories