4 ms·
It's not about developer convenience, it is about performance. There are limits to the black magic that can be done with dynamic types to eke out performance t
by clavalle 10y ago
It's not about developer convenience, it is about performance. There are limits to the black magic that can be done with dynamic types to eke out performance that can be blown past with static types.
- rbanffy 10y agoJITs help a lot with that.
- vardump 10y agoYou 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.
- qwertyuiop924 10y agoThat has nothing to do with TS, which compiles to JS, which cannot make any of those assumptions.