spaghet
spaghet2mo ago

Need help with performance

Hello, tRPC is still dreadfully slow for us. It's borderline unusable without disableSourceOfProjectReferenceRedirect": true in tsconfig.json. I've realized that it's partly because we load all procedures from all routers into memory on every autocomplete access in the TypeScript language server. How can we split up the routers? I read on GitHub that maybe they should be separate packages, but how would that even work? We specifically need to be able to infer the types of specific routers so that our TypeScript language server doesn't slow to a halt. This seems basically impossible with this current tRPC API where everything must be bundled into a single MergeRouter type. We've tried splitting things up (like for instance, a v1Router and a v2Router) so that the entire router is not enumerated but then the issue becomes namespacing, because we want v1 and v2 to be under their own routers:
router({
v1: v1Router
v2: v2Router
})
router({
v1: v1Router
v2: v2Router
})
or
mergeRouters([v1Router, v2Router])
mergeRouters([v1Router, v2Router])
We really need a way to do this. tRPC is borderline unusable for us when everything is in one router. Can anyone help here?
2 Replies
BeastFox
BeastFox2mo ago
@spaghet we had a discussion about this not so long ago here https://discord.com/channels/867764511159091230/1260588869967937556 i was initially concerned about the performance and diving head first before using it. as i mentioned in the discussion, the solution that worked for me (not saying it will necessarily work for everyone, or if it’ll be supported forever) was xTRPC which just outputs a generated type file that i use. the downside is you can no longer jump to file/type however personally ill take the extra minute or so it’ll take me to find whatever reference i’m looking for when i need to vs waiting for the language server every time other solutions were mentioned too https://github.com/algora-io/xtrpc
GitHub
GitHub - algora-io/xtrpc: Export your tRPC router to massively impr...
Export your tRPC router to massively improve language server performance and/or let your users consume your API from a typed SDK - algora-io/xtrpc
spaghet
spaghet2mo ago
We already have this out of the box with disableSourceOfProjectReferenceRedirect It’d be nice to not have to do this