> You only run type inference after you detect the hot loops.
That is the traditional approach, yes. But it will only get you so far. If you just analyze the current piece of code, you will miss out on a lot of potential optimizations.
For example, the types of the variables in the current function may be always of the same type, but without analyzing all the callers you wouldn't notice that - which means you would need to check the type each time you enter. With a more global analysis you could detect that once and be much faster.
There are a lot of other optimizations of that sort, like global variables - you can prove statically the type of many of them, just by looking in the whole program.
What is cool about this new Type Inference engine is that it is a hybrid approach. It does both local and global, and both static and dynamic analyses. You are very correct that local/dynamic type inference is a known thing, and JITs like TraceMonkey have done a form of it for a long time. But this new engine is something much better.
> If you just analyze the current piece of code, you will miss out on a lot of potential optimizations.
I didn't say that you only analyze the current piece of code. Type inference is, by nature, a global optimization. However, you don't do it until you've identified the hot spots, and you've established that it's worth investing time into it.
First, however, you get something quick running so that there are no delays, and the cost doesn't matter much to the user.
In any case, this is far from low-hanging fruit. It's very difficult to to properly, so it isn't surprising that this is the first mainstream JS engine to do it. It began as a research project - it wasn't clear it would ever end up succeeding at all.
That is the traditional approach, yes. But it will only get you so far. If you just analyze the current piece of code, you will miss out on a lot of potential optimizations.
For example, the types of the variables in the current function may be always of the same type, but without analyzing all the callers you wouldn't notice that - which means you would need to check the type each time you enter. With a more global analysis you could detect that once and be much faster.
There are a lot of other optimizations of that sort, like global variables - you can prove statically the type of many of them, just by looking in the whole program.
What is cool about this new Type Inference engine is that it is a hybrid approach. It does both local and global, and both static and dynamic analyses. You are very correct that local/dynamic type inference is a known thing, and JITs like TraceMonkey have done a form of it for a long time. But this new engine is something much better.