4 ms·
No. JS is not statically typed and that prevents the vast majority of optimizations and better memory efficiency(native types underneath).
by forgotpw1123 9y ago
No. JS is not statically typed and that prevents the vast majority of optimizations and better memory efficiency(native types underneath).
- flukus 9y agoNot to mention the levels of indirection that also impact java and c# performance, despite 20 years of people saying "compilers will improve".
- forgotpw1123 9y agoThe level of indirection is minimal, basically c++ with garbage collection. That's why they're statically typed. Both perform within a small margin of native code, with the major exceptions of vector instructions that aren't supported by all CPU's
- flukus 9y agoIn an artificial benchmark they are pretty similar, but in real world idiomatic code they are very different to c++. Nearly everything is on the heap so you've got pointers everywhere, dynamic data structures are used everywhere, virtual functions (particularly with java) and interfaces. There's is a reason java was so much slower than native code 20 years ago and that gap has been bridged by CPU progress more then compiler progress.
- pjmlp 9y agoYou are forgetting the crappy programmers as well. I lost count how many times I have reviewed code where a for loop is used instead of System.arrayCopy(). Or the times I have seen code that my CS data structures teacher would probably give a plain 0, even if done in C.
- flukus 9y agoIt's probably for the best those people aren't writing c/c++ ;) I'd love to make them code in rust, their inability to write code, to even copy/paste it will save so many maintenance problems.
- forgotpw1123 9y agoThis just isn't true. There's many Java ports of C/C++ applications and benchmarks are usually within 30%.
- coldtea 9y agoFor the easy tasks. Try a CPU heavy C/C++ app -- like an audio/video editor, number crunching of any kind, etc.
- forgotpw1123 9y agoLike I said, the major exception is SIMD instructions. AV and heavy math are a tiny fraction of applications. For these you can use JNI. There is precedent for this in Netty where they use a native poll mode driver and everything else Java, and it performs about as fast as pure C code on Techempower benchmarks
- dmsnell 9y agonote: the article mentions that the app is written in TypeScript which _is_ statically typed and therefore many of these optimizations are at least possible if not in place
- TomMarius 9y agoHe was probably talking about runtime optimizations done by CLR and JVM; this kind of optimizations is impossible even when you use TypeScript.
- yogthos 9y agoI see somebody has never heard of JIT compilers.