DEV Community

loading...

Discussion on: TypeScript is slow. What can we do about it?

Collapse
dbanisimov profile image
Denis Anisimov

Sure, TS is not blazing fast and you've pointed out the main reasons for that, mainly having a very powerful type system. It worth noting that TS analyzes not only the source files in the project, but also all of the dependencies, so the source size doesn't matter as much as the overall tree size. Most of the huge performance problems I've seen were due to some 3rd-party library trying to create very complex types, which library maintainers and TS maintainers usually take very seriously and eventually fix or improve type inference performance. It's always a good idea to keep TS version up-to-date as the team ships perf improvements in every release. (dangerous tip: you can boost TS performance by using an option --skipLibCheck)

I'm personally a bit skeptical about options 3 and 4. Native code is not a silver bullet, and a scripted interpreted language doesn't imply bad performance. IMO the way forward is for node to implement more advanced JIT optimizations and for TS to focus on higher-level optimizations, like caching and improving the IR and algorithms.

Collapse
alekseiberezkin profile image
Aleksei Berezkin Author

Thanks for an insightful comment. That's true that not only file size matters; I've noticed that the number of imports matters. This is similar to what you write about the overall tree size.

I agree that optimizations I speculate may not be the focus of the TS team; that's why I wrote it's a sci-fi 🙂 However, V8 optimizations are also not a silver bullet; V8 is already heavily optimized.

About TS optimizations — yes, agreed. There are some issues in the TS repo like “let's memoize something”, and the code I saw looks like there is not that much cached. But, you know it, caching is hard: keeping editor and TS Server in sync is very hard problem.

Anyway, looking forward for news, I believe something interesting happens soon!