4 ms·
isn't that what Typescript is shooting for?
by hprotagonist 10y ago
isn't that what Typescript is shooting for?
- tps5 10y agoAs far as I know there are no plans to directly compile (JIT or otherwise) typescript. Typescript is always (again, as far as I know) transpiled into javascript whereupon it gets JIT'd in the browser just like "normal" javascript. The gains that come from using typescript are productivity gains: in big projects static typing, generics, decorators, and interfaces are supposed to be a boost to productivity, not a boost to performance.
- pjmlp 10y agoI guess that might change in a couple of years if Typescript is still around and WebAssembly is widely available.
- munificent 10y agoNo. TypeScript's type system is intentionally unsound (it makes it easier to interop with JS and untyped code), which means they can't rely on types for efficiency.
- tbrowbdidnso 10y agoIt was my understanding that most/all of this unsoundness can be removed by telling the compiler to disallow a bunch of stuff using command line args, is this still not the case? Also even if you can't statically determine the types of some variables typescript seems to be able to determine it for most. If most of the objects are statically known would it give you a large part of the speed up of a totally static system? In Java and C# there's still some intentional holes in the type systems like the dynamic keyword or casting to object
- the_duke 10y agoAll of this is not really relevant for TypeScript, as it just transpiles to Javascript and ends up running on the used Javascript VM. Sure, sometimes you might be able to generate more efficient code by tailoring the emitted Javascript to the VM behaviour or using something like typed arrays for low level operations, but if the target language doesn't have support for certain things like type hinting, there is not much that could be gained.
- munificent 10y ago> It was my understanding that most/all of this unsoundness can be removed by telling the compiler to disallow a bunch of stuff using command line args, is this still not the case? Nope, it's never been the case, even with all the flags on. It's not about implicit casts, it's about soundness in the actual type rules. Here's an example: function append(array: Array<Object>) { array.push("not a number"); } var nums: Array<number> = []; append(nums); console.log(nums[0].toFixed()); If you run this, it throws an exception because String does not have a "toFixed()" method. > If most of the objects are statically known would it give you a large part of the speed up of a totally static system? Maybe, but it's hard to say. Once you have a single hole, if you can't check it at runtime right at the hole, then values of the wrong type can spread anywhere in the program. > In Java and C# there's still some intentional holes in the type systems like the dynamic keyword or casting to object Right. In the above example, Java and C# would throw an exception when you added the string to the array. This check has some runtime cost, but works. I believe TypeScript is also unsound around function types, which is harder to address because there's no easy place to know where to add the check.