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

Improve compilation speed (and potentially bundle size) #801

Merged
merged 5 commits into from
Jun 6, 2024

Conversation

timneutkens
Copy link
Contributor

@timneutkens timneutkens commented Jun 4, 2024

  • Ensure sideEffects: false to enable additional tree shaking
  • Use granular imports of Mantine specific components
  • Ensure css is marked as sideEffect (mirror mantine config)

While investigating a report of slow compilation in Turbopack (with Next.js) I found that BlockNote is causing all of Mantine to be compiled as it uses import * as Mantine from '@mantine/core'. @mantine/core is quite large by itself so even if tree shaking kicks in when building for production it still adds overhead in development when trying to import all components from it.

This PR ensures that only the components that are used are imported. It also adds sideEffects: false config which ensures bundlers can make more assumptions about the code and optimize it further.

Here's a screenshot from our tracing tooling:

CleanShot 2024-06-04 at 14 35 29@2x

Copy link

vercel bot commented Jun 4, 2024

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

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Jun 6, 2024 7:41pm
blocknote-website ✅ Ready (Inspect) Visit Preview Jun 6, 2024 7:41pm

Copy link

vercel bot commented Jun 4, 2024

@timneutkens is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@YousefED
Copy link
Collaborator

YousefED commented Jun 4, 2024

Bedankt @timneutkens 👋

This is great. We'll make sure this gets merged and shipped as part of next release.

Do you have a link to the specific report or is it not on github?

@YousefED YousefED requested a review from matthewlipski June 4, 2024 12:43
@timneutkens
Copy link
Contributor Author

timneutkens commented Jun 4, 2024

No worries! The report was on X, more details here: https://x.com/timneutkens/status/1797974591513542785

You can have a look at the trace files shared using next internal turbo-trace-server /path/to/trace.log (when using next@canary) in case you're curious.

# Conflicts:
#	packages/ariakit/src/menu/Menu.tsx
#	packages/ariakit/src/sideMenu/SideMenu.tsx
#	packages/mantine/src/menu/Menu.tsx
#	packages/mantine/src/sideMenu/SideMenu.tsx
@matthewlipski
Copy link
Collaborator

Thanks! I made the same changes to the Ariakit and ShadCN packages, likely those suffer from the same compilation speed issues but this wasn't seen in the report as you would ofc only use one out of the three. Additionally I added the "Mantine-" prefix to all Mantine components just to make it a bit more explicit which components are imported and which are defined.

@matthewlipski matthewlipski merged commit 7593ba3 into TypeCellOS:main Jun 6, 2024
4 checks passed
@timneutkens
Copy link
Contributor Author

Awesome, thanks Matthew! 🚀

@timneutkens
Copy link
Contributor Author

(Off topic: this is a cool project!)

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.

3 participants