180 lines
17 KiB
Markdown
180 lines
17 KiB
Markdown
# 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).
|
||
|
||
### The owner's items (second branch, from main 076b3ef): before → after, median of 3
|
||
|
||
| | webpack | Turbopack |
|
||
|---|---|---|
|
||
| JS per page without a form (compressed) | 188.1 → 179.3 KB | 181.6 → 175.5 KB |
|
||
| JS on a page with a form (the form's chunk loads there) | 188.1 → 187.7 KB | 181.6 → 183.6 KB |
|
||
| JS on the showcase (every block) | 216.4 → 218.7 KB | 209.9 → 214.0 KB |
|
||
| LCP phone, pages | 796–848 → 740–776 ms | 820–868 → 780–820 ms |
|
||
| LCP desktop, pages | 280–304 → 272–288 ms | 288–308 → 276–292 ms |
|
||
| 404 phone: LCP / CLS | 2.52 s / 0.319 → 1.84 s / 0 | 2.31 s / 0.319 → 1.72 s / 0 |
|
||
| CLS home (the headings swap to their font) | 0.036 → 0.036 | 0 → 0.036 |
|
||
| Queries per render | unchanged (19–27) | unchanged |
|
||
|
||
Raw: `webpack-1180-before.json`, `webpack-1180-after.json`, `turbopack-1180-after.json` (Turbopack "before" =
|
||
`turbopack-after.json` of the first branch).
|
||
|
||
## 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.
|
||
|
||
### The owner's decisions (2026-12-01) — all in 1.18.0
|
||
|
||
| # | Item | Decision | What was built (measured on the reference site) |
|
||
|---|---|---|---|
|
||
| 1 | Lazy 404 moves the footer (CLS 0.319, LCP 2.5 s on a phone) | yes (a) | the reference `not-found.tsx` passes a `placeholder` of its content's height (`max(290px, calc(212px + 11.5vw))`, measured 360–1920 px): CLS 0.319 → 0, LCP 2.52 → 1.90 s |
|
||
| 2 | Heading font preloaded (four font files compete with the stylesheet) | yes | `preload: false` on Fraunces in the reference layout, and so in every new site (`iapl create` keeps the call's options): phone LCP −36 to −52 ms; home CLS stays 0.036 |
|
||
| 3 | Form code on every page | yes | `BuilderForm` / `Turnstile` from `/client` are lazy wrappers (same props; the server renders the whole form); the hooks behind them lost a needless `'use client'` (each was a client boundary the entry shipped); eager ones in `@intecion/ipal-kit/client/eager`, `RenderForm Form={…}`: −8.8 KB (webpack) / −6.1 KB (Turbopack) gzip on every page without a form; a form page loads the form's chunk as before. Found on the way: the Turnstile widget (72.6 px) appeared in an empty box and moved the form — its height is now kept (73 px, `turnstileReserveHeight`) |
|
||
| 4 | Background video ignores reduced motion | yes | `BackgroundVideo` (client) pauses it after hydration for `prefers-reduced-motion`, follows a change; `Media pauseForReducedMotion={false}` |
|
||
| 5 | Consent Mode `basic` as default | **no** (stays `advanced`) | — |
|
||
| 6 | Card hover animates `box-shadow` | yes | an `::after` shadow layer fades with `opacity`; `CARD_INTERACTIVE_SHADOW_CLASS` = the 1.17 class |
|
||
| 7 | Metadata on uploads | yes, no stored variants | lossless strip of JPEG APP1/APP13/COM and PNG text/eXIf/tIME (pixels and ICC byte for byte), EXIF rotation applied once; `stripMetadata: false` |
|
||
| 8 | Doctor warnings → errors | **open** (warnings stay) | — |
|
||
## 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 — the owner's decisions (2026-12-01)
|
||
|
||
| # | Item | Decision | What was built |
|
||
|---|---|---|---|
|
||
| 9 | A default retention for form submissions | **no** | the opt-in `forms.submissionRetentionDays` stays; the doctor reports sites without one |
|
||
| 10 | MongoDB TTL indexes for the consent log and statistics | yes | `iapl_ttl` on a hidden `iaplTtlFrom` (Payload's own `createdAt` index cannot become a TTL one: Mongoose recreates it at every start — tested, IndexOptionsConflict); backfilled once from `createdAt` / `lastAt`, kept at the current `retentionDays` by `collMod` at every start; `ttlIndex: false` drops it; Postgres / SQLite unchanged. Checked in the reference gate against the real database |
|
||
| 11 | Delete `gone` cookie-review rows | **no** | — |
|
||
| 12 | Review and delete unused media in the panel | yes, manual, optional | `iapl({ unusedMedia: true })`: a notice above each upload list with a link to Payload's list filtered to the unused files (by id or by file name in a text; nothing listed when the site is too big to check every document there); deleting is Payload's bulk delete. Off by default (it adds an import-map entry); the reference site has it on; e2e `unused-media.spec.ts` |
|
||
| 13 | `maxPerDoc: 20` where versions are on | yes | the plugin's collections and globals whose versions a project turns on get 20 unless the project sets a limit; the doctor's `growth-versions-config` hints the project's own collections. Neither the plugin nor the reference site turns versions on |
|
||
|
||
### 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).
|