nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.13k stars 627 forks source link

Markdown page navigation slow on dev server when having multiple thousand md pages #2674

Closed coffeephile closed 4 months ago

coffeephile commented 4 months ago

Is your feature request related to a problem? Please describe

When having a few thousand markdown pages (2,000+), navigating between markdown pages when running the dev server can take seconds to load the new page. (I observed multiple seconds on an Intel MacBook Pro and 1~2 seconds on a M1 Pro MacBook Pro per page transition.)

This problem explicitly occurs on the local dev server, for markdown pages only, and only when having 2,000+ markdown pages, making local development quite frustrating. Build times are fine though and navigating on the SSR generated site is snappy.

Describe the solution you'd like

The problem seems to be caused by not using the content cache on localhost. https://github.com/nuxt/content/blob/3a2b5d1ec19f9232dd9f5b3487c93ff3997c7476/src/runtime/server/storage.ts#L147-L149

I assume not using the cache keeps hot reload working when files are changed, however this seems to cause the severe degradation in performance when dealing with lots of markdown pages.

To fix the issue I suggest using the cache on localhost as well, and flushing the cache when a file change is detected, to keep hot reload working. I will create a PR (draft) later to address this.

Describe alternatives you've considered

N/A

Additional context

Video showing the issue:

https://github.com/nuxt/content/assets/7602082/7582f494-1fd4-43b2-aaac-8ebc1dd8c7a6

On the video loading times are still < 1s, however the situation gets worse for more complex markdown pages.

Video showing the fix I'm working on:

https://github.com/nuxt/content/assets/7602082/15f27e2a-6923-4cfd-8581-62e831065fb8

Reproduction

I've created a project on StackBlitz to reproduce the issue. https://stackblitz.com/~/github.com/coffeephile/nuxt-huge-project-test

  1. Make sure to check out branch nuxt-content-performance-patch
  2. Install packages npm i
  3. Run NUXT_NUM_PAGES=10000 npm run dev (generate 10,000 markdown pages)
  4. Open preview in new tab (or better: run locally on your machine)

To apply the fix:

  1. Run chmod +x patch-content-localhost.sh
  2. Run ./patch-content-localhost.sh
  3. Run NUXT_NUM_PAGES=10000 npm run dev
  4. Open preview in new tab (or better: run locally on your machine)