gkr
gkr

Reputation: 79

Choosing a node.js library with pure js vs C++ add on implementation

What are the pros and cons of choosing a pure js library over a library with some C++ code ? ex. timezone-js(pure js) over node-time(cpp addon) for date with timezone support.

PS: App needs to be hosted in Heroku

Thanks

Upvotes: 0

Views: 515

Answers (2)

Yusuf X
Yusuf X

Reputation: 14633

An all-Javascript solution is easier to maintain and deploy.

One would use a C++ module instead in case:

  • there is no Javascript library for what you are trying to accomplish.
  • that part of the server is a CPU-constrained bottleneck in Javascript. This usually isn't the case, except for scenarios like media processing. After all, Node.js' design is based on the assumption that server processes spend most of their time waiting.

Since node-time isn't CPU-intensive, and a Javascript alternative exists, I recommend the simpler solution, which in this case is timezone-js.

Upvotes: 1

Michelle Tilley
Michelle Tilley

Reputation: 159105

Assuming that the libraries are functionally similar, I can think of a couple pros and cons:

C++ Pros

  • Generally faster than a pure JS implementation (this may not always be true--always test yourself)
  • Ability to do CPU-intensive work asynchronously in the thread pool

C++ Cons

  • May not compile on all platforms, usually happens when the addon requires some third-party libs
  • May be harder to debug/fix problems (depending on your level of expertise in C++/V8)

If you would prefer to use the C++ addon but are concerned about it not running on Heroku, create a small test app that uses it and deploy it. If you would prefer to use the JS lib but are concerned about speed, you'll really need to do your own real-world performance testing to see if it's actually an issue.

Upvotes: 2

Related Questions