So generally speaking, we'd expect JIT to shine with certain branchy or unpredictable code, but static compilers to shine for basic blocks. Since the hot spot of the code in question is one big basic block (no if statements, etc.), where even the loop trip count is known statically, it would be surprising in this case if a JIT outperforms a static compiler.
Static compilers just don't have the runtime information to take advantage of. Some maybe, by using profile guided optimization. JIT can always have profile guided, and adapt just for that particular case.
A sampling profiler can be pretty cheap. Just record stack state every n milliseconds, no need to instrument everything.
Actual JITting can be done on those other cores that would otherwise be idle anyways.
Empirically, the industry seems to be moving from JIT to AOT, at least for clients. .NET -> Ngen, Dalvik -> ART, JavaScript -> asm.js, etc.
(Oh, and it's a suspect assumption that there exists other cores that "would be idle anyways!")
It's tricky I'm sure, but it'll happen.
I've been playing around with an idea for a long time to write a JIT for native code. I think it's possible to speed up most native code by JITting it. Sadly it would take much more time I can afford to spend. The principle is sound, though.
It'd be possible to eliminate a lot of computation at runtime. Remove a lot of branches, use CPU model specific instructions when a suitable pattern is detected, etc. Functions could be simplified to constraints, function calls could be dynamically inlined. Spilled stack variables could be allocated in registers. Calling conventions optimized into passing more parameters in the registers. On register starved 32-bit x86, registers for parameters with effectively constant values could be converted into instructions with immediate values, saving registers for actually changing data.
There's also no reason why you can't cache previously JITted code into a file.
Static compilers can do profile guided optimization, but this only takes into account the static scenario that you profiled - not the real world scenario that the program is encountering. Your PGO is only as good as your profile.
In theory, not only is your statement untrue - but reality can turn out to be the exact opposite.
Do you have any benchmarks to back that up?
My sense is that JITet platforms lose most of the time still, but that the JITted platforms are getting closer, and occasionally win.
Static code carries a lot of overhead in some cases.
SwiftShader is a specialized JIT. It generates the code at runtime. It beats any C-code by about an order of magnitude.
https://www.transgaming.com/swiftshader/faq
All fast RegExp matchers do JIT compilation. Like PCRE. Native code just can't compete. IIRC, about an order of magnitude advantage.
Firewall rules can benefit from JIT by an order of magnitude. For example: https://wiki.freebsd.org/SummerOfCode2014/ConvertingIPFWRule...
I thought that most "native" regex engines basically amounted to small interpreters written in a compiled language. I'd be surprised if the languages that actually compile their regexes to native code are not competitive.