From 229f770cbbde82c8a033aa91961dc7c06c96fc3d Mon Sep 17 00:00:00 2001 From: Ricardo Date: Sun, 8 Mar 2026 12:52:42 +0100 Subject: [PATCH] perf: force V8 garbage collection after Eleventy builds Add global.gc() call in eleventy.after handler to release unused heap pages back to the OS. Without this, V8 keeps ~2 GB of build-time allocations resident in watch mode because there's no allocation pressure to trigger GC naturally. Requires --expose-gc in NODE_OPTIONS (set in start.sh for the watcher process). Confab-Link: http://localhost:8080/sessions/edb1b7b0-da66-4486-bd9c-d1cfa7553b88 --- eleventy.config.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/eleventy.config.js b/eleventy.config.js index 5a61754..f1c5924 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -1333,6 +1333,19 @@ export default function (eleventyConfig) { } } + // Force garbage collection after post-build work completes. + // V8 doesn't return freed heap pages to the OS without GC pressure. + // In watch mode the watcher sits idle after its initial full build, + // so without this, ~2 GB of build-time allocations stay resident. + // Requires --expose-gc in NODE_OPTIONS (set in start.sh for the watcher). + if (typeof global.gc === "function") { + const before = process.memoryUsage(); + global.gc(); + const after = process.memoryUsage(); + const freed = ((before.heapUsed - after.heapUsed) / 1024 / 1024).toFixed(0); + console.log(`[gc] Post-build GC freed ${freed} MB (heap: ${(after.heapUsed / 1024 / 1024).toFixed(0)} MB)`); + } + // WebSub hub notification — skip on incremental rebuilds if (incremental) return; const hubUrl = "https://websubhub.com/hub";