Re:Porffor: A from-scratch ahead-of-time JS engine
by wk_end on Tuesday July 30, 2024 @08:35PM
(#41115468)
I mentioned this in my original comment:
> This gives you worse-than-JIT performance on all field access, since JITs can perform dynamic shape analysis.
We're talking about using types to guide static compilation. Dynamic recompilation is moot.
Re:Porffor: A from-scratch ahead-of-time JS engine
by fenomas on Tuesday July 30, 2024 @09:22PM
(#41115685)
Oh, I thought JIT in your comment meant a single compilation. Either way, having TS type guarantees would obviously make optimizing compilers like v8's stronger, right? You seem to be arguing there's no value to it, and I don't follow that.
Re:Porffor: A from-scratch ahead-of-time JS engine
by wk_end on Tuesday July 30, 2024 @11:52PM
(#41116282)
My claim is that the guarantees that TS provides aren't strong enough to help a compiler produce stronger optimizations. Types don't just magically make code faster - there's specific reasons why they can make code faster, and TypeScript's type system wasn't designed around those reasons.
A compiler might be able to wring some things out of it (I'm skeptical about obviouslynotme's suggestions in a cousin comment, but they seem insistent) or suppress some checks if you're happy with a segfault when someone did a cast...but it's just not a type system like, say, C's, which is more rigid and thus gives the compiler more to work with.
In practice v8 does exactly what you're saying can't be done, virtually all the time for any hot function. What you mean to say is that typescript type declarations alone don't give you enough information to safely do it during a static compile step. But modern JS engines, that track object maps and dynamically recompile, do what you described.