3 ms·
There are certainly cases where type hints could be leveraged. But ultimately the way a JIT like Turbofan works is that it will do better optimizations if your
by dgb23 2y ago
There are certainly cases where type hints could be leveraged.
But ultimately the way a JIT like Turbofan works is that it will do better optimizations if your JS code is already monomorphic (functions signatures, object fields and so on).
Now TS sort of nudges you that way if you write simple TS code. But due to structural typing, expressive type golf features and the fact that TS is generally unsound I doubt it would be easy to leverage type hints much beyond that.
Here are two talks that are very much related and give some insights into how difficult these kinds of problems are:
https://thestrangeloop.com/2022/of-javascript-ahead-of-time-compilation-performance.html https://thestrangeloop.com/2022/of-javascript-ahead-of-time-...
https://www.thestrangeloop.com/2019/typing-the-untyped-soundness-in-gradual-type-systems.html https://www.thestrangeloop.com/2019/typing-the-untyped-sound...