3 ms·
You got it exactly the opposite way. Because JITs do type inference and compile specialized code with an assumption type doesn't change, they stop working when
by vardump 10y ago
You got it exactly the opposite way.
Because JITs do type inference and compile specialized code with an assumption type doesn't change, they stop working when type(s) change(s) dynamically. When that happens, JITs need to deoptimize code, which leads to a dramatic slowdown.
In other words, changing type is the case where JITs don't help and their performance nosedives, because it breaks the underlying assumptions on type stability. Type stability is needed to generate compiled binary (x86, ARM, etc.) code.
- rbanffy 10y agoNo. Perhaps I wasn't clear. The code running under a JIT will behave like the static typed code when the code (and data) allows it while the programmer didn't have the additional burden of doing the type analysis for the computer. You may be confusing dynamic typing with weak types. Also, it's perfectly fine for the JIT to generate multiple code paths that are invoked depending on runtime types even when the source code declares a single one that acts on multiple types.