From 63a3e354c8c9e5a2f987d769587a4ae6a60c8638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 20 Oct 2026 20:46:34 +0200 Subject: [PATCH] perf(boot): load route modules on first request, not all at start Next preloads every route and page module right after the server starts, about 670 here. The load runs on the event loop, so every container start showed one stall of several seconds, the first requests waited behind it, and the heap stood at about 430 MB before the first sign-in, most of it code for routes an instance rarely serves. With preloadEntriesOnStart off, each module loads on its route's first request. The same image started locally at 185 MB of heap instead of 428, with no stall, and a route's first request paid 30 to 60 ms once. --- next.config.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/next.config.ts b/next.config.ts index 6658934f0..0af3eb7aa 100644 --- a/next.config.ts +++ b/next.config.ts @@ -329,9 +329,20 @@ const nextConfig: NextConfig = { // their own body after authenticating (`src/lib/http/proxy-bypass-routes.ts`), // and every other route's own cap is at or below this. Large exports still // want a matching reverse-proxy body limit (docs/self-hosting/reverse-proxy.md). + // + // `preloadEntriesOnStart` is off. Next turns it on by default and then + // requires every route and page module (about 670 here) right after the + // server starts. That load runs on the event loop: a stall of several + // seconds in the first minute of every container, the first requests + // queued behind it, and a heap of about 430 MB before anyone has signed in, + // most of it code for routes a given instance rarely or never serves. Off, + // each module loads on its route's first request, which costs that one + // request a few tens of milliseconds; the same image measured locally + // started at 185 MB of heap instead of 428 and without the stall. experimental: { optimizePackageImports: ["recharts", "lucide-react"], proxyClientMaxBodySize: "1mb", + preloadEntriesOnStart: false, }, };