V8 engine compiles JavaScript to machine code. So, why node.js isn't faster than C? V8 engine compiles JavaScript to machine code. So, why node.js isn't faster than C? nginx nginx

V8 engine compiles JavaScript to machine code. So, why node.js isn't faster than C?


Because V8 applications are javascript applications. Even if the javascript is finally compiled to machine code the runtime characteristics are different.

For example if you call a function in an object and that object does not define the function the runtime must locate the function by traversing the prototype hierarchy, this hierarchy can change at any time during the lifetime of a program. There are clever optimizations that can be done but the overhead exists nevertheless.

There is also the memory model. Javascript is garbage collected and GC takes cpu cycles.


Because serving http requests is a different problem than regex-dna.

The fact that A is faster than B at one task doesn't say anything about what to expect from some other task.

Obligatory bad car analogy: A ham sandwich is much tastier than a porsche. Why isn't it faster from 0-60?


For one C is essentially the benchmark language for computation speed. The compliers these days are very good and produce very efficient machine code. What this means is that the upper limit for performance is what you can get with C.

In one of his presentations about node.js Ryan Dahl (the creator) said that node is about as fast as C. (but GC and other things do have an impact on performance, not to mention that V8 needs time to properly optimize things)