Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): lazy routers #5489

Draft
wants to merge 20 commits into
base: next
Choose a base branch
from
Draft

feat(server): lazy routers #5489

wants to merge 20 commits into from

Conversation

KATT
Copy link
Member

@KATT KATT commented Feb 16, 2024

Closes #4129

🎯 Changes

You can test this by installing @trpc/server@tmp / @trpc/client@tmp / .. etc

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

Copy link

vercel bot commented Feb 16, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter ❌ Failed (Inspect) Mar 22, 2024 0:01am
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Mar 22, 2024 0:01am
trpc-next-app-dir βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Mar 22, 2024 0:01am
www βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Mar 22, 2024 0:01am

Copy link

github-actions bot commented Feb 16, 2024

Diagnostics Comparison

Numbers

Metric PR next
Files 779 779 (βž– 0)
Lines of Library 40,640 40,640 (βž– 0)
Lines of Definitions 117,246 117,236 (πŸ”Ί 10)
Lines of TypeScript 4,967 4,967 (βž– 0)
Lines of JavaScript 0 0 (βž– 0)
Lines of JSON 0 0 (βž– 0)
Lines of Other 0 0 (βž– 0)
Identifiers 173,968 173,930 (πŸ”Ί 38)
Symbols 108,105 108,081 (πŸ”Ί 24)
Types 89 89 (βž– 0)
Instantiations 0 0 (βž– 0)
Memory used 167,929 171,469 (πŸ”½πŸŸ’ -3,540)
Assignability cache size 0 0 (βž– 0)
Identity cache size 0 0 (βž– 0)
Subtype cache size 0 0 (βž– 0)
Strict subtype cache size 0 0 (βž– 0)

Timings and averages

Metric PR next
max (s) 4.368 4.592 (πŸ”½πŸŸ’ -0.22)
min (s) 4.368 4.592 (πŸ”½πŸŸ’ -0.22)
avg (s) 4.368 4.592 (πŸ”½πŸŸ’ -0.22)
median (s) 4.368 4.592 (πŸ”½πŸŸ’ -0.22)
length 1 1 (βž– 0)
unstable timings

Unstable

Timings are not reliable in here

Metric PR next
I/O Read time 0.05 0.04 (πŸ”Ί 0.01)
Parse time 0.7 0.75 (πŸ”½πŸŸ’ -0.05)
ResolveTypeReference time 0.03 0.03 (βž– 0)
ResolveModule time 0.12 0.12 (βž– 0)
ResolveLibrary time 0.02 0.02 (βž– 0)
Program time 1.05 1.09 (πŸ”½πŸŸ’ -0.04)
Bind time 0.41 0.41 (βž– 0)
Total time 1.46 1.5 (πŸ”½πŸŸ’ -0.04)

Comment on lines +5 to +13
import { lazy } from '@trpc/server/unstable-core-do-not-import';
import { router } from './trpc.js';

const user = lazy(() =>
import('./routers/user.js').then((m) => {
console.log('πŸ’€ lazy loaded user router');
return m.userRouter;
}),
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @zomars here's an example on how to use it

@MathiasGruber
Copy link

I've started my migration, may take a bit to get through, but I'll give an update once I'm back to testing the lazy loading

@MathiasGruber
Copy link

Managed to bump tRPC to 11.0.0-next-beta.308 and got everything to work. Then swapped back to tmp, and now everything is working perfectly when running locally. When trying to build, however, I get errors on all pages complaining about unsafe assignment of any:
image

My current code changes from 308 to the tmp branch:
https://github.com/MathiasGruber/TheNinjaRPG/pull/72/files

@jonathanwilke
Copy link

Really excited to try this for supastarter. Is this supposed to work on edge functions too?

@MathiasGruber
Copy link

MathiasGruber commented Mar 21, 2024

Big apologies @KATT , I tried this again after rebasing on my main branch, and it seems to have been something on my end that was broken. It's working now, no issues from my entire application. Good job! πŸš€πŸŽ‰

@KATT
Copy link
Member Author

KATT commented Mar 21, 2024

Does it make a difference for the cold starts?

# Conflicts:
#	.github/workflows/release-tmp.yml
#	pnpm-lock.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚧 wip work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Lazy load routers
3 participants