nextra: Extremely slow compilation and high resource usage, even on v4 with turbopack

Describe the bug

Hey.

On the latest v4 release (version .22), the nextra-docs template takes >60sec to render the “Documentation” page, while using 300-400% CPU and 1.8GB of RAM on a modern MacBook Pro.

In of itself, a cold start taking some time isn’t a huge problem; but even next renders (after changing a single page of content) still take >10sec to complete, all while using 2GB of RAM. Turbopack doesn’t help at all here; it just uses 8x-10x times RAM, without any visible improvement to render time.

There is an old closed issue, mentioning that NextJS development is slow, but this really isn’t the case with an example app from NextJS - where builds take <100ms. The difference is more than 100x in this case between a clean example NextJS app and a Nextra Docs template, which seems suspicious 😃

To Reproduce

  1. Clone the examples/docs template from v4-v2 branch
  2. Install deps, run the NextJS server: yarn run next dev
  3. Navigate to http://localhost:3000/docs, wait for it to render
  4. Change anything in content/index.mdx
  5. See the change after 10-20sec

Expected behavior

Rerenders should probably be faster.

Screenshots

An example of how much resources initial render with Turbopack uses (some of it is shared memory, but still):

Screenshot 2024-11-08 at 23 59 44

About this issue

Most upvoted comments

Nextra 4 has 2 modes

Thank you, that cleared it up for me.

When I add console logs in Nextra’s Webpack loader, and make some changes in MDX files - I see logs with the file path of the changed file (only the initial loading of the project contains logs from all files because Nextra builds pageMap - array of existing files/folder and their exported front matter or metadata, to show proper sidebar and navigation)

I’ll try to debug it later. However, there’s one interesting finding: when I start the example docs app from the cloned Nextra repository, with package.json referencing nextra* dependencies from workspace, it flies. It’s fast. Just as fast as the website app.

However, if I extract the demo into a separate folder (not a subpath of the Nextra repository), then replace those workspace versions with 4.0.0-app-router.22 and 4.0.0-app-router.22, and install dependencies with yarn - it suddenly is slow again.

Which makes me think the problem is either in the commits after version 4.0.0-app-router.22, or in the dev/prod build 🤔

So it will be better for dx to see something on dev, something like Date.now()

Yes, makes sense. Dev builds will be closer to production, which is always good

@oprypkhantc Even though we haven’t calculated the last edit time for dev, I still feel we need some static value because we have this field in _meta file to hide this timestamp https://nextra-v2-164w6708l-shud.vercel.app/docs/docs-theme/built-ins/layout#toggle-visibility-for-timestamp

So it will be better for dx to see something on dev, something like Date.now()

Did you notice the same problems on migrated nextra.site website (docs folder)?

No, in fact it’s as fast as you describe it - hot reload updates take less than a second, and the compilation itself is ~100ms. It’s as quick as I expect it to be 😃

So having no previous experience with NextJS, as I understand it, the docs example has a fallback catch-all route that causes all of the assets to be recompiled, and the migrated Nextra site just uses Next’s static routing? And the solution is to ditch the dynamic import and dynamic routing?