# Performance review 2026-12 — method, numbers, audit, decisions The measurements and the audit behind [performance.md](../../performance.md) (1.18.0). Owner's brief (2026-12-01): the site as light as possible, everything fast and optimised, good practice required, the audit and the doctor check it, full documentation; page loading, elements, animations, resources, images. ## Method (repeatable) ```bash docker run -d --rm --name iapl-perf-mongo -p 127.0.0.1:27277:27017 mongo:7 # any local MongoDB # reference/.env: DATABASE_URI on that port, ALLOW_LOCAL_MEDIA=1, NEXT_PUBLIC_SERVER_URL=http://localhost:3370 pnpm build && (cd reference && pnpm install --ignore-workspace && pnpm seed && pnpm build) pnpm perf:measure --label=webpack-after --mongo-container=iapl-perf-mongo # starts next start itself (cd reference && pnpm exec next build --turbopack) && pnpm perf:measure --label=turbopack-after --mongo-container=iapl-perf-mongo ``` `scripts/perf-measure.mjs` + `reference/e2e/perf-lab.mjs`: Chromium (Playwright 1.65) with Lighthouse's profiles, empty cache, median of 3 runs; eight page types × phone and desktop; `/admin/login`; cold start (spawn → `/api/health`), RSS after the run, TTFB over 20 requests, and one render of each page with ISR bypassed (`x-prerender-revalidate`) counted by MongoDB's profiler. Machine: Apple silicon, Node 22.23, MongoDB 7 in Docker, Next 16.4.6, Payload 3.94.1. Raw results: `webpack-before.json`, `webpack-after.json`, `turbopack-before.json`, `turbopack-after.json` here. "Before" = local main `ee241de` (1.17.2), "after" = this branch. ## Numbers ### Server: one render of a page (ISR bypassed), webpack build | Page | Queries before → after (both bundlers) | Render ms webpack | Render ms Turbopack | |---|---|---|---| | home `/pl` | 43 → 24 | 95 → 51 | 57 → 41 | | page `/pl/o-nas` | 34 → 21 | 54 → 34 | 41 → 38 | | archive `/pl/blog` | 34 → 23 | 63 → 42 | 32 → 29 | | post | 41 → 26 | 61 → 41 | 41 → 30 | | case study | 37 → 22 | 33 → 31 | 33 → 24 | | form `/pl/wycena` | 30 → 19 | 28 → 29 | 28 → 22 | | showcase `/pl/bloki` | 42 → 27 | 68 → 62 | 73 → 50 | | 404 | 25 → 20 | 29 → 26 | 27 → 19 | | `/md/pl`, `/llms.txt`, `/llms-full.txt`, `/sitemap.xml` | 16, 22, 38, 0 — unchanged | — | All query time on a local MongoDB is ≤ 1 ms per render: the count is what costs on a remote database (one round trip each — on Coolify's Docker network ~0.2–0.5 ms, more on a managed database). A cached (ISR) page answers in 2.5–3.7 ms median, ≤ 5.4 ms p95, with 0 queries, before and after. Cold start (spawn → health) 1.0–1.6 s, no change. Memory, measured on its own (`next start`, Turbopack build: boot → 100 cached requests → 40 renders): 1.17.2 282 → 295–318 → 417–421 MiB, this branch 282 → 295 → 394 MiB (two runs each). The RSS that `perf:measure` prints after its whole run swings by ±100 MiB with garbage collection; do not compare it. ### Client: lab, median of 3, phone (Slow 4G, CPU 4×) / desktop | | Before (webpack) | After (webpack) | Before (Turbopack) | After (Turbopack) | |---|---|---|---|---| | JS per page, compressed | 191.3 KB | 188.1 KB | 184.4 KB | 181.6 KB | | JS, showcase (every block) | 219.6 KB | 216.4 KB | 212.7 KB | 209.9 KB | | CSS | 11.0 KB | 11.0 KB | 12.0 KB | 12.0 KB | | Fonts | 209.5 KB | 209.5 KB | 209.5 KB | 209.5 KB | | HTML | 17.0–19.8 KB | 17.1–19.8 KB | 17.1–19.9 KB | 17.1–19.9 KB | | Requests (home / page, phone) | 26 / 21 | 26 / 21 | 26 / 21 | 26 / 21 | | LCP phone (pages) | 788–832 ms | 780–828 ms | 796–836 ms | 820–868 ms | | LCP desktop | 284–316 ms | 288–300 ms | 284–300 ms | 288–304 ms | | CLS | 0 (home 0.036) | 0 (home 0.036) | 0 (home 0.036) | 0 (home 0–0.036) | | TBT phone | 22–25 ms | 16–23 ms | 6–13 ms | 1–7 ms | | Tap response (INP proxy) | 32–40 ms | 32–48 ms | 32–48 ms | 32–40 ms | | Script time (parse, run, hydrate), phone | 117–124 ms | 110–118 ms | 76–82 ms | 64–76 ms | | Render-blocking | 1 (the stylesheet) | 1 | 1 | 1 | | 404: LCP / CLS (phone) | 2.49 s / 0.319 | 2.50 s / 0.319 | 2.37 s / 0.319 | 2.31 s / 0.319 | | `/admin/login` JS | 843 KB | 843 KB | — | — | Lab numbers on localhost: LCP is the network profile plus render, so the differences between pages are small; the budgets and the gate catch regressions, PageSpeed Insights shows the field. On every page FCP = LCP: the first paint waits for the one stylesheet, which on the phone profile (1.6 Mbit/s) shares the line with four preloaded font files (209 KB) and the async script chunks. With Turbopack the phone's first paint came out 20–50 ms later after this branch (three runs on a quiet machine; webpack unchanged), although it ships 2.8 KB less JS and nothing new blocks: Turbopack splits the client chunks differently once the barrels are no longer one client boundary, and on that line the order of downloads moves the stylesheet a little. The fonts are the bigger lever (decision 2 below: −36 to −52 ms). ## Audit — what the plugin does, file and line, and the gain of each fix Sources: web.dev (vitals, optimize-lcp, cls, optimize-inp, font-best-practices, animations-guide, prefers-reduced-motion, third-party-facades, render-blocking-resources, serve-images-avif-webp, lcp-lazy-loading), nextjs.org/docs (caching, fonts, image, lazy-loading, package bundling), payloadcms.com/docs (queries/depth, queries/select, database/indexes). ### Built in this branch (no change to how a site looks or how editors work) | # | Finding (before) | Fix | Measured gain | |---|---|---|---| | S1 | `resolveRoute` was `cache()`d but called with `segments ?? []` — a new array each time, so React's identity comparison missed; the homepage was read in full at depth 2 (≈ 6 queries) four times per render (`src/modules/frontend/createContentHelpers.ts` resolveRoute; callers `pageRoute.tsx:123`, `createContentHelpers.ts` getPageJsonLd, `seo/createPageMetadata.ts:152`) | key by `JSON.stringify(segments ?? [])` | home 43 → 24 queries with S2–S4 | | S2 | `generatePageMetadata` uncached: the page's metadata, the reference page's alternate links and `getPageJsonLd` each built it — three × (homepage + document read in every locale) | `cache()` keyed by value | −6 queries on every page | | S3 | `slugsAcrossLocales` and `readSiteMetaConfig` read whole documents (layout in every locale) for the slug map (`seo/slugsAcrossLocales.ts:28`, `seo/readSiteMetaConfig.ts:78`) | `select: { slug: true }` | smaller reads (same count) | | S4 | `getConsentTexts` → `readPrivacyPage` read Site settings at depth 1 in every locale, populating every system page, archive and allowed page in full (`consent/getConsentTexts.ts:138`) | `select: { privacyPolicy: true }` | fewer populated pages per render | | S5 | analytics and Turnstile each read Site integrations in the same `Promise.all` (`frontend/createContentHelpers.ts` getSiteShell, `analytics/getAnalyticsConfig.ts:14`, `turnstile/config.ts:90`) | one in-flight read shared (`payload/getSiteIntegrations.ts`), nothing kept after it | −1 query per render (−2 with a form that has file blocks) | | S6 | reference: `siteJsonLd` read the Company global again instead of the cached `getCompany` (`reference/src/lib/content.ts`) | the cached getter | −1 query per render | | S7 | reference: `slugHistory.slug` without an index — queried on every unknown URL (`content/resolveRedirect.ts:96`) | `index: true` (reference `Pages.ts`, hooks.md) | a collection scan avoided per 404; nothing measurable at 30 pages | | C1 | `src/exports/client.ts` and six module barrels carried `'use client'`: the barrel was one client boundary, so every page shipped every component behind it | the directive only on the leaf components | with C2: −3.2 KB compressed JS on every page | | C2 | `LightboxProvider` imported the viewer statically (`lightbox/LightboxProvider.tsx:10`) | `lazy()` — loaded on the first open (7.3 KB raw chunk) | in C1 | | C3 | `TableOfContents` measured every heading on every scroll event (`richtext/TableOfContents.tsx:38`) | at most once per frame (rAF) | fewer forced layouts while scrolling a long article (INP) | | C4 | `Turnstile` polled every 300 ms for the life of the form (`turnstile/Turnstile.tsx:100`) | stop once rendered | no idle timer on form pages | | C5 | the cookie banner's switches, its details chevron and the cookie button animated with no regard for reduced motion (`consent/CookieBanner.tsx:139,171,361`, `CookieButton.tsx:82`) | `motion-reduce:transition-none` | WCAG 2.3.3; no change without the setting | | C6 | the reference header logo had `priority` — a second high-priority preload next to the hero (`reference/src/components/layout/Header.tsx:27`) | `Media eager` (new option: eager, no high priority, no preload) | the hero gets the first round trip (a site with a logo) | | C7 | the lazy 404 could not reserve space | `createNotFoundPage({ load, placeholder })` (default unchanged) | CLS 0.32 → 0 when the project sets its 404 height | ### Already right (kept) ISR for every page and 0 queries for a cached page; no `headers()` / `cookies()` in the layout; the consent banner in the first paint (`docs/consent.md`); theme client hints only on `/admin`; `next/font` self-hosted with `display: 'swap'`; one render-blocking stylesheet (11 KB); `mediaImageProps` sets dimensions, `sizes`, lazy and the LCP `priority`; `buildImagesConfig` serves AVIF / WebP with a 31-day cache; upload limits with an opt-in conversion (metadata dropped); `YouTubeEmbed` is a facade; Meta, LinkedIn, TikTok and Clarity wait for consent; the proxy does no database work; the 434 KB cookie database is loaded only by a scan; the sitemap has `select` and a 300 s memo. ### For the owner — yes / no (gain and cost) 1. **Lazy 404 content (CLS 0.32, LCP 2.5 s on a phone).** The 404 is fetched by a server action after hydration so that every page's payload does not carry it (pages.md). Options: (a) keep, and have the reference site set a `placeholder` of its 404 height — CLS → 0, LCP unchanged, a number to keep in sync with the content; (b) render the 404 eagerly — LCP and CLS as any page, but every page's HTML grows by the 404 content in every language (pages.md: a two-language home page as the 404 made a page 195 KB gzip instead of 146 KB). Recommendation (a). 2. **Fonts: 209.5 KB, four preloaded files** (Inter + Fraunces, latin + latin-ext). Each variable family has two subset files. Measured (Turbopack, phone, median of 5): Fraunces with `preload: false` → first paint and LCP −36 to −52 ms on home, page and post; the same 209 KB still downloads (the headings use it), and the home page's CLS goes from 0 to 0.036 (the headings swap, < 0.1). One family instead of two would save ~70 KB as well. A design decision for the reference site and the starter default. Recommendation: `preload: false` on the heading font. 3. **Form code on every page (≈ 10 KB compressed).** The catch-all route renders any block, so the contact form's client code (BuilderForm, Turnstile provider) is in every page's bundle. A `lazy()` wrapper would load it only on pages with a form; SSR stays complete. Gain −10 KB on most pages; cost: a hydration wait on the form, test effort with both bundlers. Recommendation: yes, next release. 4. **Background video and reduced motion.** `Media` (a server component) cannot know the visitor's setting, so a background video autoplays for everyone (`block-library/ui/Media.tsx:29`). A small client wrapper pausing it with `prefers-reduced-motion` adds ~1 KB to pages with a video. Recommendation: yes. 5. **Consent Mode `basic` as the default** (no request to Google before consent; already pending as a security decision). Speed gain on a first visit with GA/GTM set: one third-party origin and ~100 KB of tag less until consent. 6. **Card hover animates `box-shadow`** (`block-library/ui/Card.tsx:6`, a paint per frame, cheap on cards). A pseudo-element with `opacity` would be compositor-only; the hover looks the same. Low gain; yes if the block library is touched anyway. 7. **Upload variants (`imageSizes`) and metadata on originals.** next/image already resizes and converts on request, so stored variants mostly help the lightbox `srcSet` and R2 egress; originals under the 1.5 MB limit keep their EXIF (camera, possibly GPS). Stripping metadata on every upload re-encodes the original. Recommendation: strip metadata on upload for JPEG/PNG (privacy more than speed), variants no. 8. **Doctor performance rules: warnings now, errors later?** In 1.18.0 they warn (as asked); `perf-live` uncompressed HTML and `perf-images` could become errors in 1.19.0. ## Growth review (owner's addition, 2026-12-01): what swells the site and its database Measured on the reference site (MongoDB 7) after the full reference suite as traffic: 15 collections, the largest `pages` (15 × 9 KB); consent record 185 B, form submission 647 B, KV entry 371 B on average, plus 2–6 indexes per collection. `pnpm exec iapl-doctor --deep --only growth` on it: 2.6 s, two infos (3 submissions without a retention; 1 of 17 media unused — `logo-example-studio-1.webp`, a duplicate logo a test uploaded). | Store | Today (1.17.2 defaults) | file:line | 1.18.0 | |---|---|---|---| | consent-records | purged after 1095 days, once a day per process, only after a new record; one unbounded `deleteMany` | `consent/consentLog.ts:124,161`, `shared/purge.ts:16` | retention recorded for the doctor; `growth-retention` reports a purge that has not caught up | | stats-visits (opt-in) | purged after 90 days, same mechanism | `stats/endpoint.ts:53,153` | same | | form-submissions | **no retention, nothing deletes them**; files never stored | `forms/submitForm.ts:324` | opt-in `forms.submissionRetentionDays` (default: kept); `growth-submissions` | | payload-kv: mail-service nonces | expiry checked only on read: a nonce whose call-back never came stayed for good | `email/relay/store.ts:174` | expired nonces swept (once a day, at the next enrolment) | | payload-kv: 2FA counters, relay state | one per staff account / host; never deleted | `security/totp/verifyLimit.ts:84`, `relay/store.ts:114` | left alone: bounded; a sweep could race a live verify | | versions | the plugin turns none on; Payload keeps 100 per document / global | `payload/dist/collections/config/sanitize.js:172` | `growth-versions` (0 = unlimited, or over 50 000) | | cookie-review (opt-in) | upsert by name; `gone` rows kept | `consent/scanner/scan.ts:297` | documented | | payload-preferences / locked-documents / jobs | Payload cleans them; the plugin queues no jobs | — | — | | media | deleted with the document (disk and R2); nothing finds unused media | `storage/buildR2Storage.ts:140` | `growth-media` (counts, never deletes) | | `.next/cache/images` | 31-day TTL, no size cap | `storage/buildImagesConfig.ts:56` | `growth-disk` (info); Coolify: no volume on `.next` | | logs | the plugin writes no files | — | — | Postgres / SQLite: the same purges through Drizzle's `deleteMany`; no TTL indexes; sizes not read (counts only). ### Growth — for the owner (yes / no) 9. **A default retention for form submissions** (e.g. 365 days) on every site, existing ones included. Deletes data on live sites on their next submission. Recommendation: no default; the agent asks the client (`submissionRetentionDays`) and the doctor reports sites without one — or yes with 730 days and a loud upgrade note. 10. **MongoDB TTL indexes** for the consent log and statistics (expire `createdAt` / `lastAt` after the retention), so the purge runs even when no new record comes. Same records deleted as today, sooner on a quiet site; one index build per site at start. Recommendation: yes for 1.19.0 (opt-out), Mongo only. 11. **Delete `gone` cookie-review rows after a year.** Deletes the scanner's history. Recommendation: no. 12. **A media clean-up action in the panel** (list the unused media, delete after confirmation). Recommendation: yes, as a panel view — never automatic. 13. **`maxPerDoc: 20`** in the reference and the starter wherever versions get turned on (none today). Recommendation: yes (no data deleted until a document is saved again). ### Shared with IAWL Proposed for both products (performance.md §7): the Core Web Vitals targets and the lab profile; JS ≤ 250 KB, CSS ≤ 50 KB, fonts ≤ 250 KB and two families, ≤ 40 requests on the phone, one render-blocking stylesheet, no third-party origin before consent; images ≤ 1.5 MB and ≤ 2560 px at upload, AVIF / WebP in the width the screen needs, one high-priority LCP image, lazy below the fold. Not shared: the database budget (MongoDB queries per render here, SQL queries per request in WordPress).