Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't Node.js compiled before runtime?

Tags:

node.js

My understanding of the technology is that it is compiled on the fly into assembly. On the speed spectrum it is slower than Java but faster than Ruby and Python. On the client side an interpreter makes sense but on the server side my first thought is that compilation prior to running, or at least having the option to do so, is an optimal architecture. If the JavaScript was pre compiled in this way would it run faster than Java? Or is it something to do with weakly typed languages which means that JavaScript will always be slower than Java?

like image 889
deltanovember Avatar asked Feb 12 '12 08:02

deltanovember


1 Answers

Some of Node.js is C++ and is pre-compiled. My understanding though is that there was an effort to keep as much of it in Javascript as possible, but where performance was poor then C++ was used.

Node.js would not be possible without the V8 JavaScript Engine, which is what compiles the javascript. This engine is well-known for being extremely fast. It was built for the Chrome browser, but the performance pays off in Node.js too.

Regarding performance of Node.js, as a web server it is at least on a par with the other leading web servers like Apache+PHP. So performance is not an issue in the common use case. That said, there are faster technologies. Erlang based servers are known for being faster under concurrent loads (interestingly, Erlang is also a dynamically typed language).

For pure number crunching cpu/gpu intensive tasks, Node.js is not a good choice, unless you temper it with Fabric Engine, in which case it can be on a par with C++.

There are a couple of projects that are currently exploring speed issues with JavaScript:

  • Dart - http://www.dartlang.org/support/faq.html. (Its not just about speed but that is part of it).
  • Node Native - https://github.com/d5/node.native/
like image 53
Steve Campbell Avatar answered Oct 19 '22 23:10

Steve Campbell