TS's type system is fun but a part of me always wonders how much faster TS's compiler would be if it was written in a compiled language (assuming "good implementation", which is a big assumption!)
Probably not that much faster. V8 is very good at optimizing JS code. Typescript is slow mostly because of the complexity of its type system (which is required to make it backward compatible with existing JS code).
TypeScript is surprisingly ok for compilers
31–40 of 245 posts
Re: TypeScript is surprisingly ok for compilers
#32Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do const c = try { … }
I suspect you could do something like:
const c = attempt(() => ... );
where attempt invokes the lambda, catches any exceptions, and does what you wantRe: TypeScript is surprisingly ok for compilers
#33Earlier quoted context omitted.
The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do const c = try { … }
Zig can though: const std = @import("std"); pub fn main() !void { const stdout = std.io.getStdOut().writer(); try stdout.print("Hello, {s}!\n", .{"world"}); }
(plus some handling for diverging in the other case?)`Re: TypeScript is surprisingly ok for compilers
#34Earlier quoted context omitted.
Probably not that much faster. V8 is very good at optimizing JS code. Typescript is slow mostly because of the complexity of its type system (which is required to make it backward compatible with existing JS code).
Probably quite a bit faster if you do not have to instantiate a new V8 for every single file, considering how many files your average npm project has. I'm not certain if any contemporary build systems reuse the compiler process for multiple files
Re: TypeScript is surprisingly ok for compilers
#35TS's type system is fun but a part of me always wonders how much faster TS's compiler would be if it was written in a compiled language (assuming "good implementation", which is a big assumption!)
Basically,
> Let's say TypeScript takes over 20 seconds to type-check a medium-sized program. That's not usually because it's JS, it's often because of types that cause a combinatorial explosion.
Also
> A different runtime can afford a lot (it sounds like parallelism and start-up time in this case) but I haven't seen a CPU-bound benchmark that supports the idea of a 20x all-up speed-up.
Re: TypeScript is surprisingly ok for compilers
#36Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do const c = try { … }
const c = (
()=> {
try: {...}
}
)()Re: TypeScript is surprisingly ok for compilers
#37Earlier quoted context omitted.
Probably quite a bit faster if you do not have to instantiate a new V8 for every single file, considering how many files your average npm project has. I'm not certain if any contemporary build systems reuse the compiler process for multiple files
Why would it have to instantiate a new V8 for every file? You can just run 'tsc' in your project dir to compile all Typescript files.
Re: TypeScript is surprisingly ok for compilers
#38Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
I would think C# is easier for this due to having proper (and very convenient) pattern matching.
There are no proper sum types in C#, so 80% of the point isn't even there.
enum Season
{
Spring,
Summer,
Autumn,
Winter
}
... int PatternMatch(Season season) =>
season switch {
Season.Spring => 1,
Season.Summer => 2,
Season.Autumn => 3,
Season.Winter => 4,
// compiler can't prove the above code is exhaustive because no proper sum types
// compiler needs nonsensical branch here that diverges
_ => throw new ArgumentException("Invalid enum value for command", nameof(command)),
};Re: TypeScript is surprisingly ok for compilers
#39Ive personally decided to avoid visitor pattern bloat and Im waiting for closed enum feature in order to have compile time exhaustive check
Re: TypeScript is surprisingly ok for compilers
#40Earlier quoted context omitted.
I would think C# is easier for this due to having proper (and very convenient) pattern matching.
C# doesn't have anything resembling proper pattern matching. C#s pattern matching is akin to a marginally improved switch or if/else-if chain. C#s pattern matches aren't exhaustive, and the compiler doesn't properly check them at all.[0] There are no proper sum types in C#, so 80% of the point isn't even there. enum Season { Spring, Summer, Autumn, Winter } ... int PatternMatch(Season season) => season switch { Seaso…
Thats because c#s enum is not "closed"