Prerendering with concurrency #14080
Replies: 5 comments 4 replies
-
| 
         UPD: I hacked together a PoC patch, which works for my project. Prerender step timings on local M2 Max laptop: Timings in CI (self-hosted GH Actions with 4 cpu cores): One more run in CI, since the timings were quite different: Looks like both locally and in CI the biggest gain is when moving concurrency from 1 to 2 (and diminishing, or sometimes even negative returns after that), yielding some ~30% consistent speedup.  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         Patch (for pnpm) below: diff --git a/dist/vite.js b/dist/vite.js
index e5d6dd1c9e774d0276d573e1f02455a2f92a57ae..7620a78ed555887238bad55dd5e0e4d719ca9b7b 100644
--- a/dist/vite.js
+++ b/dist/vite.js
@@ -4126,10 +4126,15 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
     }
   }
   let buildRoutes = createPrerenderRoutes(build.routes);
-  for (let path6 of build.prerender) {
+
+  const { pMap } = require('@naturalcycles/js-lib/promise');
+  const concurrency = Number(process.env.PRERENDER_CONCURRENCY) || 1;
+  console.log({ PRERENDER_CONCURRENCY: concurrency })
+  // for (let path6 of build.prerender) {
+  await pMap(build.prerender, async path6 => {
     let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path6}/`.replace(/^\/\/+/, "/"));
     if (!matches) {
-      continue;
+      return
     }
     let leafRoute = matches ? matches[matches.length - 1].route : null;
     let manifestRoute = leafRoute ? build.routes[leafRoute.id]?.module : null;
@@ -4186,7 +4191,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
         } : void 0
       );
     }
-  }
+  }, { concurrency });
 }
 function getStaticPrerenderPaths(routes) {
   let paths = ["/"];
 | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         Would a PR be welcome, that adds a configuration property (not the env variable like in the PoC patch) named like  If yes, how should pMap be implemented - as a new dependency, vendored (copy-pasted)? (vendored is probably better, it's a small snippet and doesn't need to change over time)  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         👍  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         This has been implemented as an alpha feature in #14380 and is available for alpha testing in   | 
  
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Our build right now has a bottleneck of prerendering:
ssr: false, list of ~1000 pages given to prerender, which takes ~1 minute to execute serially.
I checked and found no configuration to enable concurrency, while other frameworks (SvelteKit, TanStack, Vike) do have concurrency configurable.
I do understand the concern of not DoS-ing/overloading the CMS, and do understand that serial execution is a safe general default setting. But I would like to see the possibility to define e.g
prerenderConcurrency: 4, which would run prerendendering concurrently (e.g with p-map).Beta Was this translation helpful? Give feedback.
All reactions