From f3be77b2bcf4ca98610ee2472a80fb6a902f5369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 1 Dec 2026 13:51:39 +0100 Subject: [PATCH 01/11] Performance measurement: pnpm perf:measure and the lab helper (phone/desktop, vitals, bytes, queries per render) Co-Authored-By: Claude Opus 5.5 --- docs/dev/perf/turbopack-before.json | 753 ++++++++++++++++++++++++++++ docs/dev/perf/webpack-before.json | 751 +++++++++++++++++++++++++++ package.json | 5 +- reference/e2e/perf-lab.mjs | 165 ++++++ scripts/perf-measure.mjs | 162 ++++++ 5 files changed, 1834 insertions(+), 2 deletions(-) create mode 100644 docs/dev/perf/turbopack-before.json create mode 100644 docs/dev/perf/webpack-before.json create mode 100644 reference/e2e/perf-lab.mjs create mode 100644 scripts/perf-measure.mjs diff --git a/docs/dev/perf/turbopack-before.json b/docs/dev/perf/turbopack-before.json new file mode 100644 index 0000000..0cf214e --- /dev/null +++ b/docs/dev/perf/turbopack-before.json @@ -0,0 +1,753 @@ +{ + "client": { + "mobile": { + "home": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 19872, + "image": 9532, + "js": 184428, + "other": 24705 + }, + "cls": 0.036, + "fcp": 816, + "inp": 40, + "interaction": "PL", + "lcp": 816, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3", + "tag": "img" + }, + "load": 2440, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 26, + "scriptMs": 76, + "status": 200, + "tbt": 6, + "thirdParty": [], + "ttfb": 151, + "url": "/pl", + "runs": 3 + }, + "page": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 17099, + "image": 8451, + "js": 184428, + "other": 13035 + }, + "cls": 0, + "fcp": 800, + "inp": 32, + "interaction": "PL", + "lcp": 800, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3", + "tag": "img" + }, + "load": 2451, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 21, + "scriptMs": 82, + "status": 200, + "tbt": 7, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/o-nas", + "runs": 3 + }, + "archive": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 16468, + "image": 5316, + "js": 184428, + "other": 18548 + }, + "cls": 0, + "fcp": 796, + "inp": 32, + "interaction": "PL", + "lcp": 796, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2443, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 22, + "scriptMs": 74, + "status": 200, + "tbt": 6, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/blog", + "runs": 3 + }, + "post": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 17059, + "image": 5316, + "js": 184428, + "other": 13035 + }, + "cls": 0, + "fcp": 796, + "inp": 32, + "interaction": "PL", + "lcp": 796, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2450, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 21, + "scriptMs": 77, + "status": 200, + "tbt": 13, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/blog/zanim-kupisz-dzialke", + "runs": 3 + }, + "caseStudy": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 16558, + "image": 4372, + "js": 184428, + "other": 13035 + }, + "cls": 0, + "fcp": 816, + "inp": 32, + "interaction": "PL", + "lcp": 816, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2436, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 20, + "scriptMs": 82, + "status": 200, + "tbt": 12, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/realizacje/dom-pod-lasem", + "runs": 3 + }, + "form": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 16307, + "image": 0, + "js": 184428, + "other": 13035 + }, + "cls": 0, + "fcp": 808, + "inp": 32, + "interaction": "PL", + "lcp": 808, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2401, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 18, + "scriptMs": 77, + "status": 200, + "tbt": 7, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/wycena", + "runs": 3 + }, + "showcase": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 36928, + "image": 2016, + "js": 212731, + "other": 24821 + }, + "cls": 0, + "fcp": 836, + "inp": 40, + "interaction": "PL", + "lcp": 836, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3", + "tag": "img" + }, + "load": 2424, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 25, + "scriptMs": 148, + "status": 200, + "tbt": 9, + "thirdParty": [ + "https://challenges.cloudflare.com" + ], + "ttfb": 151, + "url": "/pl/bloki", + "runs": 3 + }, + "notFound": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 7733, + "image": 0, + "js": 184428, + "other": 68188 + }, + "cls": 0.319, + "fcp": 2372, + "inp": 32, + "interaction": "PL", + "lcp": 2372, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2531, + "profile": "mobile", + "renderBlocking": [], + "requests": 27, + "scriptMs": 124, + "status": 404, + "tbt": 0, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/nie-ma-takiej-strony", + "runs": 3 + } + }, + "desktop": { + "home": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 19872, + "image": 9274, + "js": 184428, + "other": 71365 + }, + "cls": 0.001, + "fcp": 292, + "inp": 32, + "interaction": "PL", + "lcp": 292, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "h1" + }, + "load": 454, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 33, + "scriptMs": 26, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl", + "runs": 3 + }, + "page": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 17099, + "image": 10676, + "js": 184428, + "other": 47905 + }, + "cls": 0, + "fcp": 284, + "inp": 32, + "interaction": "PL", + "lcp": 284, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "/_next/image?url=http%3A%2F%2Flocalhost%3A3370%2Fapi%2Fmedia%2Ffile%2Flibrary.webp&w=750&q=75", + "tag": "img" + }, + "load": 456, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 28, + "scriptMs": 17, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/o-nas", + "runs": 3 + }, + "archive": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 16468, + "image": 4809, + "js": 184428, + "other": 64679 + }, + "cls": 0, + "fcp": 284, + "inp": 32, + "interaction": "PL", + "lcp": 284, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 459, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 30, + "scriptMs": 17, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/blog", + "runs": 3 + }, + "post": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 17059, + "image": 4809, + "js": 184428, + "other": 47905 + }, + "cls": 0, + "fcp": 284, + "inp": 40, + "interaction": "PL", + "lcp": 284, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 459, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 27, + "scriptMs": 18, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/blog/zanim-kupisz-dzialke", + "runs": 3 + }, + "caseStudy": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 16558, + "image": 9278, + "js": 184428, + "other": 47905 + }, + "cls": 0, + "fcp": 300, + "inp": 40, + "interaction": "PL", + "lcp": 300, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "h1" + }, + "load": 460, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 28, + "scriptMs": 19, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/realizacje/dom-pod-lasem", + "runs": 3 + }, + "form": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 16307, + "image": 0, + "js": 184428, + "other": 47905 + }, + "cls": 0, + "fcp": 284, + "inp": 40, + "interaction": "PL", + "lcp": 284, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 454, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 24, + "scriptMs": 18, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/wycena", + "runs": 3 + }, + "showcase": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 36928, + "image": 5263, + "js": 212674, + "other": 47905 + }, + "cls": 0, + "fcp": 296, + "inp": 40, + "interaction": "PL", + "lcp": 296, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 458, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/05jza-3-ce5bf.css" + ], + "requests": 30, + "scriptMs": 41, + "status": 200, + "tbt": 0, + "thirdParty": [ + "https://challenges.cloudflare.com" + ], + "ttfb": 41, + "url": "/pl/bloki", + "runs": 3 + }, + "notFound": { + "bytes": { + "css": 12004, + "font": 209501, + "html": 7733, + "image": 0, + "js": 184428, + "other": 84492 + }, + "cls": 0, + "fcp": 516, + "inp": 40, + "interaction": "PL", + "lcp": 576, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "h1" + }, + "load": 513, + "profile": "desktop", + "renderBlocking": [], + "requests": 31, + "scriptMs": 29, + "status": 404, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/nie-ma-takiej-strony", + "runs": 3 + } + }, + "admin": { + "bytes": { + "css": 98914, + "font": 0, + "html": 23023, + "image": 0, + "js": 876243, + "other": 1690 + }, + "cls": 0, + "fcp": 1052, + "inp": null, + "interaction": null, + "lcp": 1052, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "a" + }, + "load": 975, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/chunks/1l9apu4iesvci.css", + "/_next/static/chunks/3c_6gydv624zb.css", + "/_next/static/chunks/3ebvnk7qs9043.css", + "/_next/static/chunks/2h0ajyj_brp--.css", + "/_next/static/chunks/3k6de-uhqm-in.css", + "/_next/static/chunks/1z_mbvpkjhpd5.css", + "/_next/static/chunks/2do7kfo662xwp.css" + ], + "requests": 23, + "scriptMs": 410, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 90, + "url": "/admin/login", + "runs": 3 + } + }, + "date": "2026-12-01T12:14:21.329Z", + "label": "turbopack-before", + "method": "scripts/perf-measure.mjs + reference/e2e/perf-lab.mjs", + "runs": 3, + "server": { + "coldStartHealthMs": 1455, + "coldStartFirstPageMs": 1478, + "firstPageMs": 22, + "ttfb_home": { + "median": 3.9, + "p95": 6.2 + }, + "ttfb_md": { + "median": 21, + "p95": 42.4 + }, + "ttfb_sitemap": { + "median": 0.9, + "p95": 1.5 + }, + "ttfb_llms": { + "median": 28.5, + "p95": 34 + }, + "render": { + "home": { + "medianMs": 56.6, + "queries": 43, + "queryMs": 0, + "byCollection": { + "globals": 39, + "media": 24, + "pages": 57, + "forms": 9 + } + }, + "page": { + "medianMs": 40.5, + "queries": 34, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 48, + "media": 12, + "forms": 6 + } + }, + "archive": { + "medianMs": 31.7, + "queries": 34, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 45, + "media": 9, + "forms": 6, + "posts": 6 + } + }, + "post": { + "medianMs": 40.9, + "queries": 41, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 39, + "media": 15, + "posts": 27, + "forms": 6 + } + }, + "caseStudy": { + "medianMs": 32.5, + "queries": 37, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 36, + "media": 12, + "casestudies": 21, + "forms": 6 + } + }, + "form": { + "medianMs": 28.2, + "queries": 30, + "queryMs": 0, + "byCollection": { + "globals": 36, + "media": 6, + "pages": 42, + "forms": 6 + } + }, + "showcase": { + "medianMs": 72.7, + "queries": 42, + "queryMs": 0, + "byCollection": { + "globals": 30, + "pages": 57, + "media": 21, + "forms": 12, + "posts": 6 + } + }, + "notFound": { + "medianMs": 26.6, + "queries": 25, + "queryMs": 0, + "byCollection": { + "globals": 33, + "pages": 33, + "media": 9 + } + }, + "md": { + "medianMs": 29, + "queries": 16, + "queryMs": 0, + "byCollection": { + "globals": 4, + "media": 5, + "pages": 6, + "forms": 1 + } + }, + "sitemap": { + "medianMs": 2, + "queries": 0, + "queryMs": 0, + "byCollection": {} + }, + "llms": { + "medianMs": 33, + "queries": 22, + "queryMs": 0, + "byCollection": { + "globals": 4, + "media": 3, + "pages": 7, + "posts": 4, + "casestudies": 4 + } + }, + "llmsFull": { + "medianMs": 55, + "queries": 38, + "queryMs": 0, + "byCollection": { + "globals": 6, + "media": 9, + "pages": 13, + "forms": 2, + "posts": 4, + "casestudies": 4 + } + } + }, + "rssMiB": 308 + } +} diff --git a/docs/dev/perf/webpack-before.json b/docs/dev/perf/webpack-before.json new file mode 100644 index 0000000..6c8798b --- /dev/null +++ b/docs/dev/perf/webpack-before.json @@ -0,0 +1,751 @@ +{ + "client": { + "mobile": { + "home": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 19829, + "image": 9532, + "js": 191323, + "other": 24973 + }, + "cls": 0.036, + "fcp": 800, + "inp": 32, + "interaction": "PL", + "lcp": 800, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3", + "tag": "img" + }, + "load": 2492, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 26, + "scriptMs": 124, + "status": 200, + "tbt": 24, + "thirdParty": [], + "ttfb": 151, + "url": "/pl", + "runs": 3 + }, + "page": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 17074, + "image": 8451, + "js": 191323, + "other": 13185 + }, + "cls": 0, + "fcp": 788, + "inp": 40, + "interaction": "PL", + "lcp": 788, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3", + "tag": "img" + }, + "load": 2508, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 21, + "scriptMs": 117, + "status": 200, + "tbt": 22, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/o-nas", + "runs": 3 + }, + "archive": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 16520, + "image": 5316, + "js": 191323, + "other": 18759 + }, + "cls": 0, + "fcp": 796, + "inp": 32, + "interaction": "PL", + "lcp": 796, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2495, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 22, + "scriptMs": 118, + "status": 200, + "tbt": 22, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/blog", + "runs": 3 + }, + "post": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 17019, + "image": 5316, + "js": 191323, + "other": 13185 + }, + "cls": 0, + "fcp": 788, + "inp": 32, + "interaction": "PL", + "lcp": 788, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2502, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 21, + "scriptMs": 122, + "status": 200, + "tbt": 22, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/blog/zanim-kupisz-dzialke", + "runs": 3 + }, + "caseStudy": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 16514, + "image": 4372, + "js": 191323, + "other": 13185 + }, + "cls": 0, + "fcp": 792, + "inp": 32, + "interaction": "PL", + "lcp": 792, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2487, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 20, + "scriptMs": 121, + "status": 200, + "tbt": 24, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/realizacje/dom-pod-lasem", + "runs": 3 + }, + "form": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 16262, + "image": 0, + "js": 191323, + "other": 13185 + }, + "cls": 0, + "fcp": 792, + "inp": 32, + "interaction": "PL", + "lcp": 792, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2453, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 18, + "scriptMs": 118, + "status": 200, + "tbt": 23, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/wycena", + "runs": 3 + }, + "showcase": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 36904, + "image": 2016, + "js": 219569, + "other": 25103 + }, + "cls": 0, + "fcp": 832, + "inp": 40, + "interaction": "PL", + "lcp": 832, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 1000'%3", + "tag": "img" + }, + "load": 2474, + "profile": "mobile", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 25, + "scriptMs": 185, + "status": 200, + "tbt": 25, + "thirdParty": [ + "https://challenges.cloudflare.com" + ], + "ttfb": 151, + "url": "/pl/bloki", + "runs": 3 + }, + "notFound": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 7675, + "image": 0, + "js": 191323, + "other": 68911 + }, + "cls": 0.319, + "fcp": 2488, + "inp": 32, + "interaction": "PL", + "lcp": 2488, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 2400, + "profile": "mobile", + "renderBlocking": [], + "requests": 27, + "scriptMs": 195, + "status": 404, + "tbt": 0, + "thirdParty": [], + "ttfb": 151, + "url": "/pl/nie-ma-takiej-strony", + "runs": 3 + } + }, + "desktop": { + "home": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 19829, + "image": 9274, + "js": 191323, + "other": 72045 + }, + "cls": 0.001, + "fcp": 288, + "inp": 32, + "interaction": "PL", + "lcp": 288, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "h1" + }, + "load": 471, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 33, + "scriptMs": 40, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl", + "runs": 3 + }, + "page": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 17074, + "image": 10676, + "js": 191323, + "other": 48398 + }, + "cls": 0, + "fcp": 316, + "inp": 40, + "interaction": "PL", + "lcp": 316, + "lcpElement": { + "fetchpriority": "high", + "loading": "eager", + "src": "/_next/image?url=http%3A%2F%2Flocalhost%3A3370%2Fapi%2Fmedia%2Ffile%2Flibrary.webp&w=750&q=75", + "tag": "img" + }, + "load": 488, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 28, + "scriptMs": 32, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/o-nas", + "runs": 3 + }, + "archive": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 16520, + "image": 4809, + "js": 191323, + "other": 65341 + }, + "cls": 0, + "fcp": 292, + "inp": 40, + "interaction": "PL", + "lcp": 292, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 472, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 30, + "scriptMs": 34, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/blog", + "runs": 3 + }, + "post": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 17019, + "image": 4809, + "js": 191323, + "other": 48398 + }, + "cls": 0, + "fcp": 292, + "inp": 40, + "interaction": "PL", + "lcp": 292, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 471, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 27, + "scriptMs": 33, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/blog/zanim-kupisz-dzialke", + "runs": 3 + }, + "caseStudy": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 16514, + "image": 9278, + "js": 191323, + "other": 48398 + }, + "cls": 0, + "fcp": 304, + "inp": 40, + "interaction": "PL", + "lcp": 304, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "h1" + }, + "load": 468, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 28, + "scriptMs": 31, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/realizacje/dom-pod-lasem", + "runs": 3 + }, + "form": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 16262, + "image": 0, + "js": 191323, + "other": 48398 + }, + "cls": 0, + "fcp": 284, + "inp": 40, + "interaction": "PL", + "lcp": 284, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 470, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 24, + "scriptMs": 34, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/wycena", + "runs": 3 + }, + "showcase": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 36904, + "image": 5263, + "js": 219626, + "other": 48398 + }, + "cls": 0, + "fcp": 300, + "inp": 40, + "interaction": "PL", + "lcp": 300, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "p" + }, + "load": 467, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/42cf443dc3526fb0.css" + ], + "requests": 30, + "scriptMs": 44, + "status": 200, + "tbt": 0, + "thirdParty": [ + "https://challenges.cloudflare.com" + ], + "ttfb": 41, + "url": "/pl/bloki", + "runs": 3 + }, + "notFound": { + "bytes": { + "css": 11023, + "font": 209501, + "html": 7675, + "image": 0, + "js": 191323, + "other": 85467 + }, + "cls": 0, + "fcp": 516, + "inp": 32, + "interaction": "PL", + "lcp": 580, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "h1" + }, + "load": 509, + "profile": "desktop", + "renderBlocking": [], + "requests": 31, + "scriptMs": 44, + "status": 404, + "tbt": 0, + "thirdParty": [], + "ttfb": 41, + "url": "/pl/nie-ma-takiej-strony", + "runs": 3 + } + }, + "admin": { + "bytes": { + "css": 98168, + "font": 0, + "html": 23080, + "image": 0, + "js": 843253, + "other": 1690 + }, + "cls": 0, + "fcp": 1044, + "inp": null, + "interaction": null, + "lcp": 1044, + "lcpElement": { + "fetchpriority": null, + "loading": null, + "src": null, + "tag": "a" + }, + "load": 963, + "profile": "desktop", + "renderBlocking": [ + "/_next/static/css/de3d54fcc6ee5dc6.css", + "/_next/static/css/dc48c3ee3f159f65.css", + "/_next/static/css/c1e0b959dd828ab8.css", + "/_next/static/css/e5d1b6185968e333.css", + "/_next/static/css/4858144d3215dfc6.css" + ], + "requests": 20, + "scriptMs": 349, + "status": 200, + "tbt": 0, + "thirdParty": [], + "ttfb": 87, + "url": "/admin/login", + "runs": 3 + } + }, + "date": "2026-12-01T11:54:21.044Z", + "label": "webpack-before", + "method": "scripts/perf-measure.mjs + reference/e2e/perf-lab.mjs", + "runs": 3, + "server": { + "coldStartHealthMs": 1243, + "coldStartFirstPageMs": 1270, + "firstPageMs": 25, + "ttfb_home": { + "median": 3.5, + "p95": 5.3 + }, + "ttfb_md": { + "median": 30.4, + "p95": 40.8 + }, + "ttfb_sitemap": { + "median": 1.1, + "p95": 1.5 + }, + "ttfb_llms": { + "median": 26.8, + "p95": 39.6 + }, + "render": { + "home": { + "medianMs": 94.6, + "queries": 43, + "queryMs": 1, + "byCollection": { + "globals": 39, + "media": 24, + "pages": 57, + "forms": 9 + } + }, + "page": { + "medianMs": 54, + "queries": 34, + "queryMs": 1, + "byCollection": { + "globals": 36, + "pages": 48, + "media": 12, + "forms": 6 + } + }, + "archive": { + "medianMs": 62.8, + "queries": 34, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 45, + "media": 9, + "forms": 6, + "posts": 6 + } + }, + "post": { + "medianMs": 61.1, + "queries": 41, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 39, + "media": 15, + "posts": 27, + "forms": 6 + } + }, + "caseStudy": { + "medianMs": 32.6, + "queries": 37, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 36, + "media": 12, + "casestudies": 21, + "forms": 6 + } + }, + "form": { + "medianMs": 28.1, + "queries": 30, + "queryMs": 0, + "byCollection": { + "globals": 36, + "pages": 42, + "media": 6, + "forms": 6 + } + }, + "showcase": { + "medianMs": 68.3, + "queries": 42, + "queryMs": 0, + "byCollection": { + "globals": 30, + "pages": 57, + "media": 21, + "forms": 12, + "posts": 6 + } + }, + "notFound": { + "medianMs": 28.5, + "queries": 25, + "queryMs": 0, + "byCollection": { + "globals": 33, + "media": 9, + "pages": 33 + } + }, + "md": { + "medianMs": 24, + "queries": 16, + "queryMs": 0, + "byCollection": { + "globals": 4, + "media": 5, + "pages": 6, + "forms": 1 + } + }, + "sitemap": { + "medianMs": 2, + "queries": 0, + "queryMs": 0, + "byCollection": {} + }, + "llms": { + "medianMs": 36, + "queries": 22, + "queryMs": 0, + "byCollection": { + "globals": 4, + "media": 3, + "pages": 7, + "posts": 4, + "casestudies": 4 + } + }, + "llmsFull": { + "medianMs": 63, + "queries": 38, + "queryMs": 0, + "byCollection": { + "globals": 6, + "media": 9, + "pages": 13, + "forms": 2, + "posts": 4, + "casestudies": 4 + } + } + }, + "rssMiB": 340 + } +} diff --git a/package.json b/package.json index 39c95d3..e930712 100644 --- a/package.json +++ b/package.json @@ -118,15 +118,16 @@ "cookie-db:refresh": "node scripts/refresh-cookie-database.mjs", "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/", "dev": "next dev dev --turbo", - "e2e:built": "node scripts/e2e-built.mjs", - "legacy:site": "node scripts/legacy-site-check.mjs", "dev:generate-importmap": "pnpm dev:payload generate:importmap", "dev:generate-types": "pnpm dev:payload generate:types", "dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload", + "e2e:built": "node scripts/e2e-built.mjs", "generate:importmap": "pnpm dev:generate-importmap", "generate:types": "pnpm dev:generate-types", + "legacy:site": "node scripts/legacy-site-check.mjs", "lint": "eslint ./src ./test", "lint:fix": "eslint ./src ./test --fix", + "perf:measure": "node scripts/perf-measure.mjs", "prepare": "pnpm build", "prepublishOnly": "pnpm clean && pnpm build && pnpm build:starter && pnpm test:int && pnpm starter:gate", "reference:index": "node scripts/reference-index.mjs", diff --git a/reference/e2e/perf-lab.mjs b/reference/e2e/perf-lab.mjs new file mode 100644 index 0000000..4bccda1 --- /dev/null +++ b/reference/e2e/perf-lab.mjs @@ -0,0 +1,165 @@ +/** + * Lab measurements of one page in Chromium (Playwright + the DevTools protocol) — used by `pnpm perf:measure` + * (scripts/perf-measure.mjs, numbers for docs/performance.md) and by the budget gate (e2e/performance.spec.ts). + * + * Profiles follow Lighthouse's defaults so the numbers compare with PageSpeed Insights' lab data: + * - mobile: 412×823 at DPR 1.75, "Slow 4G" (150 ms RTT, 1.6 Mbit/s down, 750 kbit/s up), CPU 4× slower; + * - desktop: 1350×940, 40 ms RTT, 10 Mbit/s, CPU 1×. + * Every run is a fresh browser context (empty HTTP cache, no cookies): a first visit, the worst ordinary case. + * + * What is measured (all from the browser itself, web.dev/articles/vitals): + * ttfb, fcp, lcp (+ the LCP element: tag, src, loading, fetchpriority), cls (session windows, as web-vitals does), + * tbt (sum of long-task time over 50 ms between FCP and the end of the run: the lab stand-in for INP), + * inp (the longest Event Timing entry of one scripted interaction: a click on the page's first visible button), + * scriptMs (CDP Performance.ScriptDuration: parse, compile, run and hydrate), requests, bytes per type + * (transfer size, compressed), renderBlocking (resource timing renderBlockingStatus), thirdParty (requests to + * another origin before any consent is given). + */ +import { chromium } from '@playwright/test' + +export const PROFILES = { + desktop: { cpu: 1, network: { downloadThroughput: (10 * 1024 * 1024) / 8, latency: 40, uploadThroughput: (10 * 1024 * 1024) / 8 }, viewport: { deviceScaleFactor: 1, height: 940, isMobile: false, width: 1350 } }, + mobile: { cpu: 4, network: { downloadThroughput: (1.6 * 1024 * 1024) / 8, latency: 150, uploadThroughput: (750 * 1024) / 8 }, viewport: { deviceScaleFactor: 1.75, hasTouch: true, height: 823, isMobile: true, width: 412 } }, +} + +const OBSERVERS = `(() => { + const v = (window.__perf = { cls: 0, events: [], lcp: null, longTasks: [] }) + let win = 0, winStart = 0, winLast = 0 + new PerformanceObserver((l) => { for (const e of l.getEntries()) { + const el = e.element + v.lcp = { at: e.startTime, size: e.size, tag: el ? el.tagName.toLowerCase() : null, src: e.url || null, + loading: el && el.getAttribute ? el.getAttribute('loading') : null, + fetchpriority: el && el.getAttribute ? el.getAttribute('fetchpriority') : null } + } }).observe({ buffered: true, type: 'largest-contentful-paint' }) + new PerformanceObserver((l) => { for (const e of l.getEntries()) { + if (e.hadRecentInput) continue + if (win && e.startTime - winLast < 1000 && e.startTime - winStart < 5000) { win += e.value } else { win = e.value; winStart = e.startTime } + winLast = e.startTime + v.cls = Math.max(v.cls, win) + } }).observe({ buffered: true, type: 'layout-shift' }) + new PerformanceObserver((l) => { for (const e of l.getEntries()) v.longTasks.push([e.startTime, e.duration]) }).observe({ buffered: true, type: 'longtask' }) + new PerformanceObserver((l) => { for (const e of l.getEntries()) v.events.push({ d: e.duration, n: e.name }) }).observe({ buffered: true, durationThreshold: 16, type: 'event' }) +})()` + +/** + * @typedef {{ bytes: { css: number, font: number, html: number, image: number, js: number, other: number }, cls: number, + * fcp: null | number, inp: null | number, interaction: null | string, lcp: null | number, + * lcpElement: null | { fetchpriority: null | string, loading: null | string, src: null | string, tag: null | string }, + * load: null | number, profile: string, renderBlocking: string[], requests: number, runs?: number, scriptMs: null | number, + * status: null | number, tbt: null | number, thirdParty: string[], ttfb: null | number, url: string }} PageMeasurement + */ + +const typeOf = (resourceType, mime = '') => { + if (resourceType === 'Document') {return 'html'} + if (resourceType === 'Script') {return 'js'} + if (resourceType === 'Stylesheet') {return 'css'} + if (resourceType === 'Font') {return 'font'} + if (resourceType === 'Image' || mime.startsWith('image/')) {return 'image'} + return 'other' +} + +/** + * @param {import('@playwright/test').Browser} browser + * @param {string} url + * @param {'mobile'|'desktop'} profileName + * @param {{ interact?: boolean, settleMs?: number }} [options] + * @returns {Promise} + */ +export async function measurePage(browser, url, profileName, options = {}) { + const profile = PROFILES[profileName] + const context = await browser.newContext({ ...profile.viewport, viewport: { height: profile.viewport.height, width: profile.viewport.width } }) + const page = await context.newPage() + const cdp = await context.newCDPSession(page) + await cdp.send('Network.enable') + await cdp.send('Network.setCacheDisabled', { cacheDisabled: true }) + await cdp.send('Network.emulateNetworkConditions', { offline: false, ...profile.network }) + await cdp.send('Emulation.setCPUThrottlingRate', { rate: profile.cpu }) + await cdp.send('Performance.enable') + await page.addInitScript(OBSERVERS) + + const origin = new URL(url).origin + const requests = new Map() + cdp.on('Network.requestWillBeSent', (e) => { if (!e.request.url.startsWith('data:')) {requests.set(e.requestId, { bytes: 0, type: typeOf(e.type), url: e.request.url })} }) + cdp.on('Network.responseReceived', (e) => { const r = requests.get(e.requestId); if (r) {r.type = typeOf(e.type, e.response.mimeType); r.status = e.response.status} }) + cdp.on('Network.loadingFinished', (e) => { const r = requests.get(e.requestId); if (r) {r.bytes = e.encodedDataLength} }) + + const response = await page.goto(url, { waitUntil: 'load' }) + await page.waitForLoadState('networkidle').catch(() => {}) + await page.waitForTimeout(options.settleMs ?? 1000) + + let interaction = null + if (options.interact !== false) { + // INP stand-in: one click on the first visible button (menu toggle, cookie settings, theme): a real handler runs + const button = page.locator('button:visible').first() + if (await button.count()) { + interaction = (await button.getAttribute('aria-label')) ?? (await button.innerText()).slice(0, 40) + await button.click({ timeout: 5000 }).catch(() => { interaction = null }) + await page.waitForTimeout(500) + } + } + + const nav = await page.evaluate(() => { + const n = performance.getEntriesByType('navigation')[0] + const fcp = performance.getEntriesByName('first-contentful-paint')[0] + const blocking = performance.getEntriesByType('resource').filter((r) => r.renderBlockingStatus === 'blocking').map((r) => r.name) + return { blocking, domContentLoaded: n.domContentLoadedEventEnd, fcp: fcp ? fcp.startTime : null, load: n.loadEventEnd, ttfb: n.responseStart } + }) + const vitals = await page.evaluate(() => window.__perf) + const { metrics } = await cdp.send('Performance.getMetrics') + const metric = (name) => metrics.find((m) => m.name === name)?.value ?? 0 + await context.close() + + const list = [...requests.values()] + const bytes = { css: 0, font: 0, html: 0, image: 0, js: 0, other: 0 } + for (const r of list) {bytes[r.type] += r.bytes} + const fcp = nav.fcp ?? 0 + const tbt = vitals.longTasks.filter(([start]) => start >= fcp).reduce((sum, [, d]) => sum + Math.max(0, d - 50), 0) + const round = (n) => (n == null ? null : Math.round(n)) + return { + bytes: Object.fromEntries(Object.entries(bytes).map(([k, b]) => [k, Math.round(b)])), + cls: Math.round(vitals.cls * 1000) / 1000, + fcp: round(nav.fcp), + inp: vitals.events.length ? round(Math.max(...vitals.events.map((e) => e.d))) : interaction ? 0 : null, + interaction, + lcp: round(vitals.lcp?.at), + lcpElement: vitals.lcp ? { fetchpriority: vitals.lcp.fetchpriority, loading: vitals.lcp.loading, src: vitals.lcp.src ? vitals.lcp.src.replace(origin, '') : null, tag: vitals.lcp.tag } : null, + load: round(nav.load), + profile: profileName, + renderBlocking: nav.blocking.map((u) => u.replace(origin, '')), + requests: list.length, + scriptMs: round(metric('ScriptDuration') * 1000), + status: response?.status() ?? null, + tbt: round(tbt), + thirdParty: [...new Set(list.filter((r) => !r.url.startsWith(origin)).map((r) => new URL(r.url).origin))], + ttfb: round(nav.ttfb), + url: url.replace(origin, ''), + } +} + +export const median = (values) => { + const sorted = values.filter((v) => typeof v === 'number').sort((a, b) => a - b) + if (!sorted.length) {return null} + const mid = Math.floor(sorted.length / 2) + return sorted.length % 2 ? sorted[mid] : Math.round(((sorted[mid - 1] + sorted[mid]) / 2) * 1000) / 1000 +} + +/** + * The median of `runs` measurements for every number; the rest from the last run. + * @param {import('@playwright/test').Browser} browser + * @param {string} url + * @param {'mobile'|'desktop'} profileName + * @param {number} [runs] + * @param {{ interact?: boolean, settleMs?: number }} [options] + * @returns {Promise} + */ +export async function measureMedian(browser, url, profileName, runs = 3, options = {}) { + const all = [] + for (let i = 0; i < runs; i++) {all.push(await measurePage(browser, url, profileName, options))} + const last = all.at(-1) + const out = { ...last, runs } + for (const key of ['cls', 'fcp', 'inp', 'lcp', 'load', 'requests', 'scriptMs', 'tbt', 'ttfb']) {out[key] = median(all.map((r) => r[key]))} + out.bytes = Object.fromEntries(Object.keys(last.bytes).map((k) => [k, median(all.map((r) => r.bytes[k]))])) + return out +} + +export const launch = () => chromium.launch() diff --git a/scripts/perf-measure.mjs b/scripts/perf-measure.mjs new file mode 100644 index 0000000..4d93334 --- /dev/null +++ b/scripts/perf-measure.mjs @@ -0,0 +1,162 @@ +#!/usr/bin/env node +/** + * pnpm perf:measure — measures the BUILT reference site (reference/) and writes the numbers to a JSON file. + * The method behind docs/performance.md → "How the plugin is measured"; repeat it after a change and compare. + * + * Before: reference/.env filled (local seeded MongoDB, ALLOW_LOCAL_MEDIA=1), the plugin built, `pnpm build` in + * reference/ (webpack; `pnpm exec next build --turbopack` for Turbopack). The script starts `next start` itself. + * + * node scripts/perf-measure.mjs --label=webpack-before [--runs=3] [--port=3370] [--out=file.json] [--no-server] + * + * Server side: cold start (spawn → /api/health answers, → first page), memory (RSS of the server after the run), + * TTFB of a cached (ISR) page over 20 requests, and the cost of RENDERING each page once: the request carries + * Next's `x-prerender-revalidate` header (the on-demand revalidation Next uses itself), so the page is rendered + * now and not served from the ISR cache; MongoDB's profiler (level 2, the database in DATABASE_URI) counts every + * query that render made and their time. The profiler is switched off again at the end. + * Client side: e2e/perf-lab.mjs (Lighthouse's mobile and desktop profiles), the median of --runs runs per page. + */ +import { execFileSync, spawn } from 'node:child_process' +import { readFileSync, writeFileSync } from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +import { launch, measureMedian } from '../reference/e2e/perf-lab.mjs' + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') +const site = path.join(root, 'reference') +const arg = (name, fallback) => process.argv.find((a) => a.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback +const label = arg('label', 'run') +const runs = Number(arg('runs', 3)) +const env = Object.fromEntries(readFileSync(path.join(site, '.env'), 'utf8').split('\n').filter((l) => /^[A-Z0-9_]+=/.test(l)).map((l) => [l.slice(0, l.indexOf('=')), l.slice(l.indexOf('=') + 1)])) +const port = Number(arg('port', new URL(env.NEXT_PUBLIC_SERVER_URL ?? 'http://localhost:3370').port || 3370)) +const base = `http://localhost:${port}` +const out = arg('out', path.join(root, 'docs', 'dev', 'perf', `${label}.json`)) + +/** The page types measured: one of each template the reference site has (AGENTS.md → Site map). */ +export const PAGES = { + home: '/pl', + page: '/pl/o-nas', + archive: '/pl/blog', + post: '/pl/blog/zanim-kupisz-dzialke', + caseStudy: '/pl/realizacje/dom-pod-lasem', + form: '/pl/wycena', + showcase: '/pl/bloki', + notFound: '/pl/nie-ma-takiej-strony', +} + +// --- MongoDB profiler (through the mongo container's shell when DATABASE_URI is local; else skipped) --- +const dbUri = process.env.DATABASE_URI ?? env.DATABASE_URI +const dbName = new URL(dbUri).pathname.slice(1) +const container = arg('mongo-container', process.env.PERF_MONGO_CONTAINER ?? '') +const mongo = (js) => { + if (!container) {return null} + return execFileSync('docker', ['exec', container, 'mongosh', '--quiet', dbName, '--eval', js], { encoding: 'utf8' }).trim() +} +const profileOn = () => mongo('db.setProfilingLevel(0); db.system.profile.drop(); db.setProfilingLevel(2); "ok"') +const profileOff = () => mongo('db.setProfilingLevel(0); "ok"') +const profileRead = () => { + const raw = mongo(`JSON.stringify(db.system.profile.find({ ns: { $not: /system\\.profile$/ }, op: { $in: ['query','command','getmore','insert','update','remove'] } }, { millis: 1, ns: 1, op: 1, 'command.find': 1, 'command.aggregate': 1, 'command.count': 1 }).toArray())`) + if (raw == null) {return null} + const rows = JSON.parse(raw).filter((r) => !r.command || r.command.find || r.command.aggregate || r.command.count || r.op !== 'command') + mongo('db.setProfilingLevel(0); db.system.profile.drop(); db.setProfilingLevel(2); "ok"') + const byCollection = {} + for (const r of rows) {const c = r.ns.split('.').slice(1).join('.'); byCollection[c] = (byCollection[c] ?? 0) + 1} + return { byCollection, count: rows.length, ms: rows.reduce((s, r) => s + (r.millis ?? 0), 0) } +} + +const waitFor = async (url, timeoutMs = 60000) => { + const start = Date.now() + while (Date.now() - start < timeoutMs) { + try { + if ((await fetch(url)).ok) {return Date.now() - start} + } catch {} + await new Promise((r) => setTimeout(r, 100)) + } + throw new Error(`${url} did not answer in ${timeoutMs} ms`) +} +const timed = async (url, init) => { + const t = performance.now() + const res = await fetch(url, { redirect: 'manual', ...init }) + await res.arrayBuffer() + return { ms: performance.now() - t, res } +} +const pct = (values, p) => { + const s = [...values].sort((a, b) => a - b) + return Math.round(s[Math.min(s.length - 1, Math.floor((p / 100) * s.length))] * 10) / 10 +} +const rssOf = (pid) => { + // the server is `node … next start` under pnpm: sum the process tree's RSS (KiB → MiB) + const tree = execFileSync('ps', ['-A', '-o', 'pid=,ppid=,rss='], { encoding: 'utf8' }).trim().split('\n').map((l) => l.trim().split(/\s+/).map(Number)) + const ids = new Set([pid]) + for (let changed = true; changed;) { + changed = false + for (const [p, pp] of tree) {if (ids.has(pp) && !ids.has(p)) {ids.add(p); changed = true}} + } + return Math.round(tree.filter(([p]) => ids.has(p)).reduce((s, [, , rss]) => s + rss, 0) / 1024) +} + +const result = { client: {}, date: new Date().toISOString(), label, method: 'scripts/perf-measure.mjs + reference/e2e/perf-lab.mjs', runs, server: {} } +let server = null +if (!process.argv.includes('--no-server')) { + // another server on the port would be measured instead of this build (and a stale .next answers 404 for assets) + if (await fetch(`${base}/api/health`).then(() => true, () => false)) { + console.error(`[perf] ${base} already answers: stop that server first (lsof -ti tcp:${port} | xargs kill) or pass --no-server`) + process.exit(2) + } + const t0 = Date.now() + server = spawn('pnpm', ['start'], { cwd: site, env: { ...process.env, PORT: String(port) }, detached: true, stdio: ['ignore', 'ignore', 'inherit'] }) + result.server.coldStartHealthMs = await waitFor(`${base}/api/health`) + const first = await timed(`${base}${PAGES.home}`) + result.server.coldStartFirstPageMs = Date.now() - t0 + result.server.firstPageMs = Math.round(first.ms) +} +try { + // TTFB of a cached page and of the dynamic routes the plugin serves + for (const [name, p] of Object.entries({ home: PAGES.home, md: '/md/pl', sitemap: '/sitemap.xml', llms: '/llms.txt' })) { + await timed(`${base}${p}`) + const times = [] + for (let i = 0; i < 20; i++) {times.push((await timed(`${base}${p}`)).ms)} + result.server[`ttfb_${name}`] = { median: pct(times, 50), p95: pct(times, 95) } + } + // the cost of one render of each page (ISR bypassed), with the queries it made + const manifest = JSON.parse(readFileSync(path.join(site, '.next', 'prerender-manifest.json'), 'utf8')) + const previewModeId = manifest.preview?.previewModeId + result.server.render = {} + if (profileOn() == null) {result.server.queriesNote = 'no --mongo-container: query counts not measured'} + for (const [name, p] of Object.entries(PAGES)) { + profileRead() + const renders = [] + for (let i = 0; i < 3; i++) {renders.push((await timed(`${base}${p}`, { headers: previewModeId ? { 'x-prerender-revalidate': previewModeId } : {} })).ms)} + const q = profileRead() + result.server.render[name] = { medianMs: pct(renders, 50), queries: q ? Math.round(q.count / 3) : null, queryMs: q ? Math.round(q.ms / 3) : null, byCollection: q?.byCollection } + } + for (const [name, p] of Object.entries({ md: '/md/pl', sitemap: '/sitemap.xml', llms: '/llms.txt', llmsFull: '/llms-full.txt' })) { + profileRead() + const { ms } = await timed(`${base}${p}`) + const q = profileRead() + result.server.render[name] = { medianMs: Math.round(ms), queries: q?.count ?? null, queryMs: q?.ms ?? null, byCollection: q?.byCollection } + } + profileOff() + + const browser = await launch() + for (const profile of ['mobile', 'desktop']) { + result.client[profile] = {} + for (const [name, p] of Object.entries(PAGES)) { + result.client[profile][name] = await measureMedian(browser, `${base}${p}`, profile, runs) + const r = result.client[profile][name] + console.log(`[perf] ${profile.padEnd(7)} ${name.padEnd(9)} LCP ${r.lcp} CLS ${r.cls} TBT ${r.tbt} INP ${r.inp} JS ${r.bytes.js} CSS ${r.bytes.css} req ${r.requests}`) + } + } + result.client.admin = await measureMedian(browser, `${base}/admin/login`, 'desktop', runs, { interact: false }) + await browser.close() + if (server) {result.server.rssMiB = rssOf(server.pid)} +} finally { + profileOff() + if (server) { + try { process.kill(-server.pid, 'SIGTERM') } catch {} // the whole process group: pnpm and next start + } +} +writeFileSync(out, `${JSON.stringify(result, null, 2)}\n`) +console.log(`[perf] written ${path.relative(root, out)}`) +console.log(JSON.stringify(result.server, null, 1)) +process.exit(0) From 1d6108765c6edda46319e2c3aa321597c6dbb261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 1 Dec 2026 13:51:39 +0100 Subject: [PATCH 02/11] Fewer queries per render: resolveRoute and page metadata cached by value, select for slug-only reads, one Site integrations read Home 43 -> 24 MongoDB queries per render, other pages -36 to -44 %. Co-Authored-By: Claude Opus 5.5 --- reference/src/collections/Pages.ts | 2 +- reference/src/lib/content.ts | 8 ++++---- src/modules/consent/getConsentTexts.ts | 2 ++ src/modules/frontend/createContentHelpers.ts | 21 ++++++++++++++++---- src/modules/payload/getSiteIntegrations.ts | 11 +++++++++- src/modules/seo/readSiteMetaConfig.ts | 1 + src/modules/seo/slugsAcrossLocales.ts | 1 + 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/reference/src/collections/Pages.ts b/reference/src/collections/Pages.ts index b9b4201..5e635e8 100644 --- a/reference/src/collections/Pages.ts +++ b/reference/src/collections/Pages.ts @@ -28,7 +28,7 @@ export const Pages: CollectionConfig = { { name: 'layout', type: 'blocks', blocks: pageBlocks, minRows: 1 }, buildSummaryField(), // aiSummary — GEO (llms.txt, MCP) buildNoindexField(), - { name: 'slugHistory', type: 'array', admin: { components: rowLabel('slug', 'Old address'), readOnly: true }, fields: [{ name: 'slug', type: 'text' }], labels: { plural: 'Old addresses', singular: 'Old address' } }, + { name: 'slugHistory', type: 'array', admin: { components: rowLabel('slug', 'Old address'), readOnly: true }, fields: [{ name: 'slug', type: 'text', index: true }], labels: { plural: 'Old addresses', singular: 'Old address' } }, ], hooks: { afterChange: [revalidate.afterChange], diff --git a/reference/src/lib/content.ts b/reference/src/lib/content.ts index 9c1047b..4bf7ee4 100644 --- a/reference/src/lib/content.ts +++ b/reference/src/lib/content.ts @@ -2,9 +2,8 @@ import { faqItemsFromLayout } from '@intecion/ipal-kit/blocks' // @starter:if localBusiness import { buildLocalBusinessJsonLd, createContentHelpers } from '@intecion/ipal-kit' -import { getPayload } from 'payload' import { contentConfig } from '@/content.config' -import { i18nConfig, type Locale } from '@/i18n.config' +import { i18nConfig } from '@/i18n.config' // @starter:else //: import { createContentHelpers } from '@intecion/ipal-kit' //: @@ -65,8 +64,9 @@ export const { // @starter:if localBusiness // LocalBusiness from the Company global (replaces the default WebSite + Organization from Site settings) siteJsonLd: async ({ baseUrl, locale }) => { - const payload = await getPayload({ config }) - const company = await payload.findGlobal({ slug: 'company', locale: locale as Locale }) + // the layout's cached getter: one Company read per request, not two (docs/performance.md → server) + const { getCompany } = await import('./globals') + const company = await getCompany(locale) return [ buildLocalBusinessJsonLd({ address: { city: company.address?.city ?? undefined, country: company.address?.country ?? 'PL', postalCode: company.address?.postalCode ?? undefined, street: company.address?.street ?? undefined }, diff --git a/src/modules/consent/getConsentTexts.ts b/src/modules/consent/getConsentTexts.ts index 4cab004..85b2e13 100644 --- a/src/modules/consent/getConsentTexts.ts +++ b/src/modules/consent/getConsentTexts.ts @@ -141,6 +141,8 @@ async function readPrivacyPage(payload: BasePayload, settingsSlug: string): Prom slug: settingsSlug as never, depth: 1, locale: 'all' as never, + // only the privacy page: without it depth 1 brought every page Site settings points at, in every language + select: { privacyPolicy: true } as never, })) as { privacyPolicy?: unknown } const page = settings.privacyPolicy return page && typeof page === 'object' ? (page as PrivacyPage) : null diff --git a/src/modules/frontend/createContentHelpers.ts b/src/modules/frontend/createContentHelpers.ts index b64aa71..a8584c8 100644 --- a/src/modules/frontend/createContentHelpers.ts +++ b/src/modules/frontend/createContentHelpers.ts @@ -233,12 +233,18 @@ export function createContentHelpers({ }) /** What does this URL point at? Routing only — no listing data. */ - const resolveRoute = cache( + // React cache() compares arguments by identity: the page passes the params' array, metadata and JSON-LD pass + // `segments ?? []` — a new array each time — so every caller missed and the homepage (no segments) was read in + // full four times per render. The segments travel as a string key instead (measured: docs/performance.md). + const resolveRoute = (locale: string, segments: string[] | undefined, page: number): Promise => + resolveRouteCached(locale, JSON.stringify(segments ?? []), page) + const resolveRouteCached = cache( async ( locale: string, - segments: string[] | undefined, + segmentsKey: string, page: number, ): Promise => { + const segments = JSON.parse(segmentsKey) as string[] const payload = await getCachedPayload() const settings = (await getSettings(locale)) as Record return resolveRouteRaw({ @@ -266,10 +272,17 @@ export function createContentHelpers({ * } */ let pageMetadata: ReturnType | undefined - const generatePageMetadata = async ( + // One build per request and URL: the page's generateMetadata, its render (alternate links) and getPageJsonLd all + // ask for it — uncached that was three times the homepage and document reads in every locale (measured: 43 → fewer + // MongoDB queries per render, docs/performance.md). The segments travel as a string so separate arrays still match. + const pageMetadataCached = cache(async (locale: string, segmentsKey: null | string, page: number): Promise => + buildPageMetadata(locale, segmentsKey === null ? undefined : (JSON.parse(segmentsKey) as string[]), page)) + const generatePageMetadata = (locale: string, segments: string[] | undefined, page = 1): Promise => + pageMetadataCached(locale, segments === undefined ? null : JSON.stringify(segments), page) + const buildPageMetadata = async ( locale: string, segments: string[] | undefined, - page = 1, + page: number, ): Promise => { if (!i18n) { throw new Error('[iapl] createContentHelpers: pass `i18n` to use generatePageMetadata.') diff --git a/src/modules/payload/getSiteIntegrations.ts b/src/modules/payload/getSiteIntegrations.ts index 09bdee3..e15bf83 100644 --- a/src/modules/payload/getSiteIntegrations.ts +++ b/src/modules/payload/getSiteIntegrations.ts @@ -101,5 +101,14 @@ export function getSiteIntegrations>( payload: BasePayload, options?: GlobalQueryOptions, ): Promise { - return findSiteIntegrations(payload, options) + if (options && Object.keys(options).length) {return findSiteIntegrations(payload, options)} + // Callers that start together (the layout reads analytics IDs and the Turnstile key side by side) share ONE read + // while it is in flight; the next call reads again, so nothing is cached between requests or after a save. + const pending = inFlight.get(payload) + if (pending) {return pending as Promise} + const read = findSiteIntegrations(payload).finally(() => inFlight.delete(payload)) + inFlight.set(payload, read) + return read } + +const inFlight = new WeakMap>() diff --git a/src/modules/seo/readSiteMetaConfig.ts b/src/modules/seo/readSiteMetaConfig.ts index f1fc765..e3bec4a 100644 --- a/src/modules/seo/readSiteMetaConfig.ts +++ b/src/modules/seo/readSiteMetaConfig.ts @@ -82,6 +82,7 @@ export async function readSiteMetaConfig({ collection: pagesSlug as never, depth: 0, locale: 'all' as never, + select: { slug: true } as never, // only the slug map is used: not the layout in every language })) as { slug?: unknown } const slugField = homeDoc.slug if (slugField && typeof slugField === 'object') { diff --git a/src/modules/seo/slugsAcrossLocales.ts b/src/modules/seo/slugsAcrossLocales.ts index ef243cd..f289f01 100644 --- a/src/modules/seo/slugsAcrossLocales.ts +++ b/src/modules/seo/slugsAcrossLocales.ts @@ -30,6 +30,7 @@ export async function slugsAcrossLocales({ collection: collection as never, depth: 0, locale: 'all', + select: { slug: true } as never, // only the slug map is used: not the layout in every language })) as { slug?: unknown } return doc.slug && typeof doc.slug === 'object' From 21073d98d038882dc45f451ca81517086ff853c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 1 Dec 2026 13:51:39 +0100 Subject: [PATCH 03/11] Client: no 'use client' on barrels, lazy lightbox viewer, rAF table of contents, Turnstile polling stops, reduced motion, Media eager, 404 placeholder option Co-Authored-By: Claude Opus 5.5 --- reference/src/components/layout/Header.tsx | 2 +- src/exports/client.ts | 3 ++- src/modules/accessibility/client.ts | 3 ++- src/modules/analytics/client.ts | 3 ++- src/modules/block-library/ui/Media.tsx | 6 ++++-- src/modules/consent/CookieBanner.tsx | 6 +++--- src/modules/consent/CookieButton.tsx | 2 +- src/modules/consent/client.ts | 3 ++- src/modules/frontend/pageRoute.tsx | 7 ++++++- src/modules/lightbox/LightboxProvider.tsx | 9 ++++++--- src/modules/lightbox/client.ts | 3 ++- src/modules/media/mediaProps.ts | 9 +++++++-- src/modules/pages/NotFoundLoader.tsx | 20 +++++++++----------- src/modules/richtext/TableOfContents.tsx | 18 ++++++++++++++---- src/modules/stats/client.ts | 3 ++- src/modules/turnstile/Turnstile.tsx | 10 +++++++--- src/modules/turnstile/client.ts | 3 ++- 17 files changed, 72 insertions(+), 38 deletions(-) diff --git a/reference/src/components/layout/Header.tsx b/reference/src/components/layout/Header.tsx index 8c6241c..9b1b1c7 100644 --- a/reference/src/components/layout/Header.tsx +++ b/reference/src/components/layout/Header.tsx @@ -24,7 +24,7 @@ export async function Header({ header, locale, settings, themeLabel }: Props) {
- {logo ? : null} + {logo ? : null} {typeof settings?.siteName === 'string' ? settings.siteName : null}