TypeCellOS / BlockNote

A React Rich Text Editor that's block-based (Notion style) and extensible. Built on top of Prosemirror and Tiptap.
https://www.blocknotejs.org/
Mozilla Public License 2.0
5.9k stars 384 forks source link

Improve compilation speed (and potentially bundle size) #801

Closed timneutkens closed 4 weeks ago

timneutkens commented 1 month ago

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

vercel[bot] commented 1 month ago

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
vercel[bot] commented 1 month ago

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

A member of the Team first needs to authorize it.

YousefED commented 1 month ago

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?

timneutkens commented 1 month ago

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.

matthewlipski commented 4 weeks ago

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.

timneutkens commented 3 weeks ago

Awesome, thanks Matthew! 🚀

timneutkens commented 3 weeks ago

(Off topic: this is a cool project!)