Experiments with 'Static' JavaScript: As Fast As Native Code?
mozakai.blogspot.com
mozakai.blogspot.com
1) Given a perfect compiler, once compiled any interpreted code would be as fast as a native implementation.
2) How good a job your compiler does is dependent on many things, majorly the complexity of the code being compiled.
Fannkuch is extremely trivial code and really boils down to indirect array manipulation. It's interesting when comparing native/interpreted code because it indicates how much overhead is incurred with indirect memory access, but it's not something that provides any indication of how statically compiled javascript would generally perform against native code.
You don't need static typing in order to compile to machine code.
The generated code for something like "a = b + c" is very, very different if you know at compile-time whether b and c are strings or numbers or something else. Modern JavaScript VMs go to a lot of effort to guess or infer type information before JIT compilation.
Isn't that what all modern JavaScript engines do? If so, how are the results for the experiment so good? My guess is that he didn't take the compilation time into account in his own method.