Another solution would be to use the proper, statically and strictly typed programming languages with AOT compilation. Rust, Swift, Kotlin - these are the best of production-level languages that can produce both native code and WebAssembly. There are other, similar languages as well. They key point - when compiler knows more about your intentions (e.g. strict and sound type system) it can optimize it better. Especially with LTO or PGO.