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

perf: split up routers to separate lambdas #8041

Merged
merged 37 commits into from
May 5, 2023

Conversation

juliusmarminge
Copy link
Contributor

@juliusmarminge juliusmarminge commented Mar 31, 2023

What does this PR do?

Splits up the all tRPC routers into their own API routes. (Edited by @keithwillcode)

New bundle sizes

The slots router is massive compared to all the rest endpoints together...

image

Old bundle size

Seems like the analyzer doesn't really compare apples to apples here, as it states the previous bundle size is tiny. Not sure what's going on there, does it not take into account the size of the appRouter since it's just joining in others?

CleanShot 2023-04-01 at 15 26 09@2x

But, given that the entire appRouter is imported which comes in at 334kB, that should give an idea of the actual size:

CleanShot 2023-04-01 at 15 24 40@2x

Fixes # (issue)

Environment: Staging(main branch) / Production

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)

How should this be tested?

  • Test the entire app basically to ensure no tRPC routes have been broken.

@vercel
Copy link

vercel bot commented Mar 31, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cal ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2023 3:49pm
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2023 3:49pm
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2023 3:49pm

@vercel
Copy link

vercel bot commented Mar 31, 2023

@juliusmarminge is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 31, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@PeerRich PeerRich added 🧹 Improvements Improvements to existing features. Mostly UX/UI High priority Created by Linear-GitHub Sync labels Apr 3, 2023
@KATT KATT mentioned this pull request Apr 4, 2023
1 task
@emrysal emrysal marked this pull request as ready for review April 4, 2023 11:55
@emrysal emrysal requested a review from a team April 4, 2023 11:55
@emrysal emrysal marked this pull request as draft April 4, 2023 11:56
@hariombalhara hariombalhara self-requested a review as a code owner May 3, 2023 05:05
@hariombalhara hariombalhara requested a review from a team May 3, 2023 05:05
@hariombalhara hariombalhara dismissed zomars’s stale review May 3, 2023 10:25

E2Es are fixed now. There were route assertions which changed.

@keithwillcode
Copy link
Contributor

keithwillcode commented May 3, 2023

Documenting here for clarity. There was a separate test done in #8551 that verified when accessing the route /api/trpc/viewer.public.i18n under a different API route of /api/trpc/public/i18n, the time difference in cold start load was down to 2 seconds from 15+. When I realized the full path forward was to separate all routers into their own API routes so we avoid a compounding effect of loading lots of routers into 1 core router, I brought those changes back over here to build upon the work @juliusmarminge had started.

The effect this will have is if you look at the network traffic for cold starts on pages in the app, you will now see multiple tRPC calls take upwards of 3 seconds to load but since they run concurrently, the effect is not compounded, which was what resulted in such long load times.

Copy link
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

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

LGTM. tested some core features locally

@zomars zomars mentioned this pull request May 4, 2023
1 task
Copy link
Contributor

@roae roae left a comment

Choose a reason for hiding this comment

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

Great job!! 🚀

Left a comment about how we can make sure this runs on separate lambdas. we can do it in other PR or add it here before we merge if you agree, your choice @keithwillcode

Comment on lines +15 to +18
/**
* We deploy our tRPC router on multiple lambdas to keep number of imports as small as possible
* TODO: Make this dynamic based on folders in trpc server?
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

to make sure this is deployed on different lambdas maybe we should have a slightly different configuration on each path as discussed in slack.

Here an example, this changes must be added to the vercel.json

cc @emrysal

b803c61

imagen

@keithwillcode
Copy link
Contributor

keithwillcode commented May 4, 2023 via email

@keithwillcode keithwillcode merged commit cdba192 into calcom:main May 5, 2023
@keithwillcode keithwillcode changed the title refactor: split up routers to separate lambdas perf: split up routers to separate lambdas May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High priority Created by Linear-GitHub Sync 🧹 Improvements Improvements to existing features. Mostly UX/UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants