perf: add build timing instrumentation to OG and unfurl hooks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
svemagie
2026-03-19 22:13:41 +01:00
parent 596a5bf6c9
commit 39aaf0b79d

View File

@@ -1361,6 +1361,7 @@ export default function (eleventyConfig) {
// Exit code 2 = batch complete, more work remains → re-spawn. // Exit code 2 = batch complete, more work remains → re-spawn.
// Manifest caching makes incremental builds fast (only new posts get generated). // Manifest caching makes incremental builds fast (only new posts get generated).
eleventyConfig.on("eleventy.before", () => { eleventyConfig.on("eleventy.before", () => {
console.time("[og] image generation");
const contentDir = resolve(__dirname, "content"); const contentDir = resolve(__dirname, "content");
const cacheDir = resolve(__dirname, ".cache"); const cacheDir = resolve(__dirname, ".cache");
const siteName = process.env.SITE_NAME || "My IndieWeb Blog"; const siteName = process.env.SITE_NAME || "My IndieWeb Blog";
@@ -1413,14 +1414,19 @@ export default function (eleventyConfig) {
} catch (err) { } catch (err) {
console.error("[og] Image generation failed:", err.message); console.error("[og] Image generation failed:", err.message);
} }
console.timeEnd("[og] image generation");
}); });
// Pre-fetch unfurl metadata for all interaction URLs in content files. // Pre-fetch unfurl metadata for all interaction URLs in content files.
// Populates the disk cache BEFORE templates render, so the synchronous // Populates the disk cache BEFORE templates render, so the synchronous
// unfurlCard filter (used in nested includes like recent-posts) has data. // unfurlCard filter (used in nested includes like recent-posts) has data.
eleventyConfig.on("eleventy.before", async () => { eleventyConfig.on("eleventy.before", async () => {
console.time("[unfurl] prefetch");
const contentDir = resolve(__dirname, "content"); const contentDir = resolve(__dirname, "content");
if (!existsSync(contentDir)) return; if (!existsSync(contentDir)) {
console.timeEnd("[unfurl] prefetch");
return;
}
const urls = new Set(); const urls = new Set();
const interactionProps = [ const interactionProps = [
@@ -1443,7 +1449,10 @@ export default function (eleventyConfig) {
}; };
walk(contentDir); walk(contentDir);
if (urls.size === 0) return; if (urls.size === 0) {
console.timeEnd("[unfurl] prefetch");
return;
}
// Free parsed markdown content before starting network-heavy prefetch // Free parsed markdown content before starting network-heavy prefetch
if (typeof global.gc === "function") global.gc(); if (typeof global.gc === "function") global.gc();
@@ -1465,6 +1474,7 @@ export default function (eleventyConfig) {
} }
} }
console.log(`[unfurl] Pre-fetch complete.`); console.log(`[unfurl] Pre-fetch complete.`);
console.timeEnd("[unfurl] prefetch");
}); });
// Post-build hook: pagefind indexing + WebSub notification // Post-build hook: pagefind indexing + WebSub notification