I don't understand why people keep making js-to-native compilers. the result is always less performance that what modern js engines can do to the original source code, because all those runtime behaviours the author mentions build up really fast. js engines actually run the code and figure out the types and such to create highly optimized machine code.
I wonder how much optimization will it bring to compared to existing JS runtimes such as V8.<p>Thanks to competing world for web browsers, JS runtimes not only efficiently parse to optimized native code but also provide really good JIT compilation benefits.<p>Speculative optimization for V8 - <a href="https://ponyfoo.com/articles/an-introduction-to-speculative-optimization-in-v8" rel="nofollow">https://ponyfoo.com/articles/an-introduction-to-speculative-...</a><p>Parallel and Concurrent GC - <a href="https://v8.dev/blog/trash-talk" rel="nofollow">https://v8.dev/blog/trash-talk</a><p>Good summary on 10 years of V8 - <a href="https://v8.dev/blog/10-years" rel="nofollow">https://v8.dev/blog/10-years</a>
A lot of research and hard work has gone into TclQuadCode [0], which compiles Tcl (which is even more dynamic than JavaScript) into machine code via LLVM.<p>The authors indicated at one point it took around 5 PhDs to get it going.<p>[0] <a href="https://core.tcl.tk/tclquadcode/dir?ci=trunk" rel="nofollow">https://core.tcl.tk/tclquadcode/dir?ci=trunk</a>
I actually think this is possible; and started prototyping it (because esprima is awesome, and not to many other languages have an equivalent that's so easy to use).<p>Some thoughts:
I think it's easier to target C++ than C, since C++ can help you write more type generic code. I think it's easy to generate tagged unions, then for optimizations try to prove monomorphism. Finally, it may be simpler to start off with support for typescript, and fail to compile if there are any ANY types. I do think it's possible though. JS/TS -> C++ -> WASM (yes, I was out of my mind when I thought of this)
With all the dynamic stuff Javascript has it seems really difficult to create performant C code.<p>There is a PHP to .NET compiler which probably has similar problems. On second thought that one is probably easier because .NEt has a dynamic runtime.
I wonder why people still try write transpiler from JS to C/C++ or LLVM (which make sense at least). But this not performant way and usually produce much bigger overhead than jit vm which use speculative optimizations.<p>Some projects:
1. <a href="https://github.com/fabiosantoscode/js2cpp" rel="nofollow">https://github.com/fabiosantoscode/js2cpp</a>
2. <a href="https://github.com/raphamorim/js2c" rel="nofollow">https://github.com/raphamorim/js2c</a>
3. <a href="https://github.com/ammer/js2c" rel="nofollow">https://github.com/ammer/js2c</a>
4. <a href="https://github.com/NectarJS/nectarjs" rel="nofollow">https://github.com/NectarJS/nectarjs</a>
5. <a href="https://github.com/ovr/StaticScript" rel="nofollow">https://github.com/ovr/StaticScript</a>