cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

refactor: split up routers to separate lambdas

Open juliusmarminge opened this issue 2 years ago • 11 comments

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.

juliusmarminge avatar Mar 31 '23 12:03 juliusmarminge

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[bot] avatar Mar 31 '23 12:03 vercel[bot]

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Mar 31 '23 12:03 vercel[bot]

📦 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! 🙌

github-actions[bot] avatar Mar 31 '23 12:03 github-actions[bot]

Latest main changes to reduce the appStore size look to have been succesful:

image

emrysal avatar Apr 05 '23 17:04 emrysal

📦 Next.js Bundle Analysis for @calcom/web

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

Two Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/apps/[slug]/[...pages] 387.08 KB 620.2 KB 177.20% (🟢 -0.15%)
/auth/setup 79.95 KB 313.07 KB 89.45% (🟢 -0.19%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/-

github-actions[bot] avatar Apr 11 '23 18:04 github-actions[bot]

📦 Next.js Bundle Analysis for @calcom/web

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

Two Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/apps/[slug]/[...pages] 387.3 KB 620.41 KB 177.26% (🟢 -0.15%)
/auth/setup 80.16 KB 313.28 KB 89.51% (🟢 -0.19%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/-

github-actions[bot] avatar Apr 12 '23 02:04 github-actions[bot]

📦 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! 🙌

github-actions[bot] avatar Apr 12 '23 02:04 github-actions[bot]

This PR is being marked as stale due to inactivity.

github-actions[bot] avatar Apr 27 '23 00:04 github-actions[bot]

I've gotten this branch up to date with main and have brought over my changes from #8551 to separate all tRPC routers into their own API routes.

keithwillcode avatar May 01 '23 16:05 keithwillcode

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.

keithwillcode avatar May 03 '23 12:05 keithwillcode

The way it’s written now, since the api routes are separated into different folders, Vercel already creates separate functions for each one. We don’t have to include this config to ensure those are created distinctly. We can if we want to change config of course though.

keithwillcode avatar May 04 '23 13:05 keithwillcode