framework icon indicating copy to clipboard operation
framework copied to clipboard

perf(vite): remove vite warm up

Open antfu opened this issue 3 years ago • 4 comments

🔗 Linked issue

❓ Type of change

  • [ ] 📖 Documentation (updates to the documentation or readme)
  • [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
  • [x] 👌 Enhancement (improving an existing functionality like performance)
  • [ ] ✨ New feature (a non-breaking change that adds functionality)
  • [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This reduces the start-up time of nuxt.com repo with viteNode: true (nuxi dev to first render on the browser) from 60s to 40s on my M1 Max Macbook Pro.

Reasoning:

  • Vite will now do warm-up for sync deps automatically.
  • Our warm-up uses server.transformRequest(url) for both client/server. Where the server bundler actually needs server.transformRequest(url, { ssr: true }), which is actually using a different plugin pipeline and caches.

📝 Checklist

  • [ ] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

antfu avatar Jul 29 '22 10:07 antfu

Deploy Preview for nuxt3-docs canceled.

Name Link
Latest commit f0a73115c5c3d544d0fadedc6a8c591610d23a9f
Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62fa622147e8880008a4a2e5

netlify[bot] avatar Jul 29 '22 10:07 netlify[bot]

Vite will now do warm-up for sync deps automatically.

Does Vite also warmups the entrypoint in background? (Same for vite-node with ssr condition)

Our warm-up uses server.transformRequest(url) for both client/server. Where the server bundler actually needs server.transformRequest(url, { ssr: true }), which is actually using a different plugin pipeline and caches.

Nice find and probably to late to fix if warmup is not relevant anymore 😅

pi0 avatar Jul 29 '22 10:07 pi0

I also tried to only warm up the entry (and let Vite crawl the deps), it ends up around 50s start-up time. I guess it might be because it occupied the execution time of other parts. I could do a more detailed benchmarking, and probably try delaying the warm-up with a timeout.

antfu avatar Jul 29 '22 10:07 antfu

I suggest this method to benchmark:

  • Cleanup cache with nuxi cleanup each time
  • In parallel initiate a fetch to http://localhost:300 and start nuxi dev
    • Measure time to first byte for SSR perf
  • Open a new browser window ensuring no other windows are open
    • Measure time to load for entrypoint scripts

pi0 avatar Jul 29 '22 10:07 pi0

Let's experiment this as an option that we can disable. (sorry there were merge conflicts otherwise would push to same PR) ~> #6647.

We should also track this:

Our warm-up uses server.transformRequest(url) for both client/server. Where the server bundler actually needs server.transformRequest(url, { ssr: true }), which is actually using a different plugin pipeline and caches.

~> #6649

pi0 avatar Aug 15 '22 15:08 pi0