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

docs: add documentation on minimizing lambda bundle #167

Merged
merged 3 commits into from
Oct 12, 2023

Conversation

khuezy
Copy link
Collaborator

@khuezy khuezy commented Jul 29, 2023

fixes: #166

Edit: one of the changes breaks server actions 😢
We might be better off removing the dev modules inside build.ts...

@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2023

⚠️ No Changeset found

Latest commit: 876be70

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Jul 29, 2023

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

Name Status Preview Comments Updated (UTC)
open-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2023 5:44pm

@jayair
Copy link
Contributor

jayair commented Aug 2, 2023

Do we want to merge this @khuezy?

@seed-deploy seed-deploy bot temporarily deployed to pr167 August 3, 2023 00:02 Inactive
@khuezy
Copy link
Collaborator Author

khuezy commented Aug 3, 2023

Yes, I added a note on server actions. Feel free to edit and merge.

@JanStevens
Copy link
Contributor

JanStevens commented Aug 25, 2023

FYI im using the following list:

'./node_modules/@next/swc-darwin-x64',
'./node_modules/@next/swc-linux-arm64-gnu',
'./node_modules/@next/swc-linux-arm64-musl',
'./node_modules/@next/swc-linux-x64-gnu',
'./node_modules/@next/swc-linux-x64-musl',
'./node_modules/@next/swc-win32-arm64-msvc',
'./node_modules/@next/swc-win32-ia32-msvc',
'./node_modules/@next/swc-win32-x64-msvc',
'./node_modules/@swc/core-linux-x64-gnu',
'./node_modules/@swc/core-linux-x64-musl',
'./node_modules/@swc/core-linux-x64-gnux32',
'./node_modules/caniuse-lite',
'./node_modules/uglify-js',
'./node_modules/watchpack',
'./node_modules/@esbuild',
'./node_modules/@rollup',
'./node_modules/@webassemblyjs',
'./node_modules/esbuild/linux',
'./node_modules/rollup',
'./node_modules/terser',

@khuezy
Copy link
Collaborator Author

khuezy commented Aug 25, 2023

Thanks @JanStevens , I'll put up a PR to remove those at buildtime. Since this isn't a blocker though, I'll defer this until after the other PRs.

Actually this is the PR... I'll update it later.

@khuezy
Copy link
Collaborator Author

khuezy commented Oct 12, 2023

@conico974 PTAL

@khuezy khuezy requested a review from conico974 October 12, 2023 16:38
Copy link
Collaborator

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

LGTM, i've added some comments, but they're not strictly necessary.

It's only webpack that we need for server actions right ?

'esbuild',
'uglify-js',
'watchpack',
'webassemblyjs'
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could probably add sharp here, people might have installed but it's not needed outside of the image optimization function.
We should probably add a comment to explain it


#### Reducing Bundle Size

Next will incorrectly trace dev dependencies to be included in the output `node_modules`, which will significantly increase the lambda bundle. For example, the @swc/core-\* binary is ~33MB!
Copy link
Collaborator

Choose a reason for hiding this comment

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

With 13.5.1+ they probably will not even end up in node_modules, a big part is now bundled by next and may end up in one of the bundle

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I built w/ 13.5.4 and the core-darwin-arm64 binary was still there unfortunately

#### Unzipped size must be smaller than 262144000 bytes

AWS Lambda has an unzipped size limit of 250MB. If your app is over this limit, then it is most likely using a node_module library that is too large for serverless or there is a large dev dependency getting bundled.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add that what's important is the .open-next/server-function folder, and the rest are mostly irrelevant.
We could also add that a big bundle size will increase cold start a lot

@khuezy
Copy link
Collaborator Author

khuezy commented Oct 12, 2023

LGTM, i've added some comments, but they're not strictly necessary.

It's only webpack that we need for server actions right ?

As far as I know but it's been awhile since I tested (13.3 I think).

@khuezy khuezy merged commit d291e6a into sst:main Oct 12, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bundled node_modules bloat
4 participants