Massive TypeScript performance issues
We have an app that I would consider quite small with about 20 routes of which about 10 are top level routes. Type checking (
tsc --no-emit) with the router type registered takes about 2-3 minutes on my Macbook Pro. Without it, it takes 14 seconds. The TypeScript language service becomes unusable, error feedback in a file in VSCode turn from instantly after an edit to taking about 30 seconds.
I already tried adding type aliases to typeof router, explicitly annotating validateSearch functions, extracting routes into their own files. These seem to be tips from the TypeScript documentation, but they don't help.
I am also getting error messages about type instantiation:
Looking at the conversations here in the chat, it seems like I am the only one who is experiencing these massive performance problems. So I am beginning to think if we are doing something fundamentally wrong. Any feedback or tips would be appreciated.
Is this normal? Any ideas what could cause this?
One of my ideas is that graphql-codegen could be playing badly with router. It could cause unnecessary reevaluations of a lot of types. This could explain the issues of the language service, but tsc should evaluate everything exactly once and is also 10 times slower...4 Replies
harsh-harlequin•3y ago
All of routers recursive types have depth guards, so I’d be surprised if it was any one type from it. It could be a circular type that isn’t easy to see…
variable-lime•3y ago
I have exactly the same problem the last couple of weeks. Not using gql at all. Shocking performance for m1 pro.
@Hendrik Niemann
If you ever figure it out I'd appreciate an update
Do you have any tips on what sort of circular dependencies the ignorant user may be easily prone to creating when using router?
harsh-harlequin•3y ago
Honestly this happens most often with recursive routes types that provide auto complete for generics you feed it.
Try and remove any of your own types from the system that may be recursive or deep and see if that helps. Then try and find out where you’re passing those.
Also, I’m reworking some internals on the router. It could help. Who knows.
conscious-sapphireOP•3y ago
Thanks for the responses, Tanner, I will keep trying to simplify the types. I will also specifically look for recursions. Will report back with results 🫡