mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-04-02 16:44:56 +02:00
perf: add periodic GC to og-cli to reclaim WASM native memory
Satori (Yoga WASM) and Resvg (Rust WASM) allocate native memory that V8 doesn't track against the heap limit. Without periodic GC, the JS wrappers accumulate and native RSS grows to ~2 GB during OG image generation for 3400+ posts. - Add --expose-gc to og-cli spawn - Call global.gc() every 50 images to reclaim native memory - Log final RSS/heap for monitoring Confab-Link: http://localhost:8080/sessions/edb1b7b0-da66-4486-bd9c-d1cfa7553b88
This commit is contained in:
@@ -1124,6 +1124,7 @@ export default function (eleventyConfig) {
|
||||
try {
|
||||
execFileSync(process.execPath, [
|
||||
"--max-old-space-size=768",
|
||||
"--expose-gc",
|
||||
resolve(__dirname, "lib", "og-cli.js"),
|
||||
contentDir,
|
||||
cacheDir,
|
||||
|
||||
15
lib/og.js
15
lib/og.js
@@ -298,6 +298,8 @@ export async function generateOgImages(contentDir, cacheDir, siteName) {
|
||||
let skipped = 0;
|
||||
const newManifest = {};
|
||||
const SAVE_INTERVAL = 10;
|
||||
const GC_INTERVAL = 50;
|
||||
const hasGC = typeof global.gc === "function";
|
||||
|
||||
for (const filePath of mdFiles) {
|
||||
const raw = readFileSync(filePath, "utf8");
|
||||
@@ -335,10 +337,21 @@ export async function generateOgImages(contentDir, cacheDir, siteName) {
|
||||
if (generated % SAVE_INTERVAL === 0) {
|
||||
writeFileSync(manifestPath, JSON.stringify(newManifest, null, 2));
|
||||
}
|
||||
|
||||
// Force GC to reclaim Satori/Resvg WASM native memory.
|
||||
// V8 doesn't track native heap (Satori Yoga WASM + Resvg Rust WASM),
|
||||
// so without periodic GC the JS wrappers accumulate and native memory
|
||||
// grows unbounded. With --expose-gc this keeps peak RSS under control.
|
||||
if (hasGC && generated % GC_INTERVAL === 0) {
|
||||
global.gc();
|
||||
}
|
||||
}
|
||||
|
||||
if (hasGC) global.gc();
|
||||
writeFileSync(manifestPath, JSON.stringify(newManifest, null, 2));
|
||||
const mem = process.memoryUsage();
|
||||
console.log(
|
||||
`[og] Generated ${generated} images, skipped ${skipped} (cached or have photos)`,
|
||||
`[og] Generated ${generated} images, skipped ${skipped} (cached or have photos)` +
|
||||
` | RSS: ${(mem.rss / 1024 / 1024).toFixed(0)} MB, heap: ${(mem.heapUsed / 1024 / 1024).toFixed(0)} MB`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user