DEV Community

loading...

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

Collapse
jwp profile image
John Peters

Does same failure happen in Visual Studio Code?

Collapse
alekseiberezkin profile image
Aleksei Berezkin Author

Yes. However, because VSCode eats less CPU itself, the overall effect is less noticeable.

Collapse
jwp profile image
John Peters

Your analysis of this issue is over the top good! Was wondering if breaking the work down into separate composable parts would help. For example in TS I'm just know breaking into using more function libraries to replace any code that doesn't really follow my own strict separation of concerns. Even if I spot for example 15+ lines of code in a component, that has for example 20 other functions in it. I split them off into one file named for the concern which contains one or more functions of only that filename's concern.

What I found in doing this is that when in development mode (using webpack development server) none of those functions get recompiled because, well, because they didn't change. This makes for ultra fast reloads in the browser.

But there's a small price to pay for this, in that some changes never get picked up (probably mostly my fault) until I do a new build. Why this happens is unknown to me but I don't think the hot reload logic is bullet proof. TS function files work better than Class files because the functions are first class citizens just like a class. They are better because if we allow a class to contain all the functions, creating an instance loads all the functions! When using the function method the loading is only for the imported function.

Also in regards to the language service differences between WebStorm and Visual Studio Code, this indicates that WebStorm is doing something different that may be adding to the problem.

Thread Thread
alekseiberezkin profile image
Aleksei Berezkin Author

Separation of concerns is always a good thing, regardless of the language. For TS the most performant dev environment is a lot of small files.

I also used to encounter wepback stuck, not sure what's that. This happens sometimes for Babel and JS as well.

Regarding WS vs VSCode tsserver usage — yes, they are doing it slightly differently. However, the result CPU load is the same. Again, I'm talking about tsserver in isolation. Additional load from WS is a subject for completely different post 😀