3 ms·
A couple obvious reasons would be compiled vs interpreted, and static vs dynamic, both of which bear some inherit runtime performance cost.
by setr 7y ago
A couple obvious reasons would be compiled vs interpreted, and static vs dynamic, both of which bear some inherit runtime performance cost.
- jashmatthews 7y agoCompiled vs interpreted is not a useful distinction. Until fairly recently when Ignition was introduced, V8 had no interpreter. All the JS was compiled by the first tier “full codegen” The bigger difference is that the JVM is heavily optimized for performance after a long warmup and V8 needs to produce relatively fast code early during page loading. Java being much more static certainly helps warmup time but ultimately doesn’t really affect final performance. LuaJIT can beat C in some cases once it has time to compile all traces needed.
- The_rationalist 7y agoV8 needs to produce relatively fast code early during page loading So for e.g backend js programs is it possible to ask v8 to take more time to optimize?
- saagarjha 7y agoWhy would would you want it to take longer to optimize?
- The_rationalist 7y agoTo get more time to generate betten codegen so a faster program (but slower "launch time")
- saagarjha 7y agoMost VMs will recompile long-running hot code; I’d assume V8 does this as well.
- PeCaN 7y agoModern JS engines only interpret cold functions, and static vs dynamic doesn't matter once type information has been collected. The real reason is that HotSpot has 10+ more years of work put into it than V8.
- ufo 7y agoStatic vs dynamic still matters if the program is doing "dynamic stuff", where "dynamic stuff" means any thing that the JIT compiler is currently not able to optimize.
- PeCaN 7y agoThat's fair, but that's also stuff that you just can't really do in Java in general¹, so it's not useful for a comparison. The fact is that the vast majority of JavaScript code is pretty static and there's nothing preventing it from running as fast as Java other than man-decades of compiler engineering. ― ¹ Possibly excluding reflection. It's been a long time since I used the Java reflection APIs and I have no idea if you can do things like add class fields named after arbitrary strings at runtime. Even if you could, presumably this bails out of jitted code so the situation is basically the same as in JS.