Comment by josephg
3 years ago
If types were added to javascript it could also dramatically improve the performance of javascript virtual machines (V8 and friends). It seems so silly to me that I write typescript, then the types are erased from my code, sent to the browser, and then the browser tries to infer them as part of its own optimization process.
Adding types to javascript proper would be fantastic.
This proposal is not about adding types to JavaScript. This proposal is about new syntax for comments in JavaScript. Virtual machine will not use this information.
> If types were added to javascript it could also dramatically improve the performance of javascript virtual machines
Are you sure? In my understanding modern JS engines basically makes type inference on the code anyway, and in the rare case when types are observed to change at runtime, it is special-cased. So static types might simplify this but I dont see how it would dramatically improve performance.
And chances are(?) typescript code are to a larger degree monomorphic than javascript making the JIT more efficient(?).
At least typescript discourage writing functions where the parameters can have wildly different types since this is un-ergonomic and/or hard to type.
This is a good read: https://medium.com/dartlang/dart-and-the-performance-benefit...
That said I really doubt JS will actually get sound static types ever. Typescript is not sound.
That Medium link 404s for me.
1 reply →