From cbe1dd1f20cb836cb86cd25a9a6add84be536fc6 Mon Sep 17 00:00:00 2001 From: Rinat Madyarov <218408024+lukavtz@users.noreply.github.com> Date: Fri, 6 Nov 2026 00:27:40 +0300 Subject: [PATCH] Cover all 31 web performance topics in the router The table was missing six symptoms and merged two others into one row. It now has one row per recipe, numbered 1 to 31, plus measurement guidance, an order of work and the traps that follow from it. changed: skills/webperf/SKILL.md verified: npm test -> 26 pass, 0 fail; grep -c rows -> 31 assuming: none not done: none question: none --- skills/webperf/SKILL.md | 105 ++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 36 deletions(-) diff --git a/skills/webperf/SKILL.md b/skills/webperf/SKILL.md index 3def7c4..4186c41 100644 --- a/skills/webperf/SKILL.md +++ b/skills/webperf/SKILL.md @@ -11,47 +11,80 @@ One topic per slice. If the fix does not apply to this stack, say so and change ## Start from a measurement -A performance change without a before number is a guess. Take the number first: -Lighthouse on a throttled profile, the Network panel, `EXPLAIN`, or the server log. -Repeat the same measurement after the fix and report both. +A performance change without a before number is a guess. Take the number first, with the instrument that matches the symptom: + +| Symptom class | Instrument | +| --- | --- | +| First paint, layout shift, bundle size | Lighthouse on a throttled profile, or the framework build report | +| Network shape: duplicates, waterfalls, weight | Network panel, throttled preset, cache disabled | +| Request timing on the server | `EXPLAIN`, query log, trace spans | +| Real users | Core Web Vitals from RUM, not a lab run | + +Write the before number down, make the change, repeat the same measurement, report both. A change with no pair of numbers is not finished. + +## Order of work + +Cheapest fix first, because most slow pages are fixed by the first three rows: + +1. Headers, compression, cache policy, static from a CDN. Config only, no code. +2. Assets: images, fonts, third-party scripts, bundle splitting. +3. Requests: duplicates, waterfalls, payload size, pagination. +4. Rendering: skeletons, streaming, optimistic updates, virtualization. +5. Data: N+1, indexes, column selection, pooling, caching. +6. Infrastructure: regions, replicas, background queues. Ask before touching any of it. + +Stop after the measurement improves. Do not continue into the next group because the list is there. ## Route by symptom -| Symptom | Fix | Verify with | -| --- | --- | --- | -| Blank screen while data loads | Skeleton shaped like the real content; errors rendered apart | Throttled network: shape appears, not a spinner | -| Heavy images | WebP/AVIF with the original as fallback, explicit width and height | Network: modern type, no layout shift | -| Images below the fold | `loading="lazy"` for those only | First paint loads fewer requests | -| External fonts | Self-host woff2, only used weights, `font-display` | Network: fonts from own origin | -| Large JS bundle | Split by route, dynamic import for editors, maps, charts | Build report before and after | -| Third-party scripts | `defer`/`async`, load after first interaction | Page interactive without them | -| Slow first content | Server render or static generation for public pages | View source contains the text | -| Long lists | Virtualize; keep scroll, search and focus | DOM holds only visible rows | -| Duplicate API calls | One call per screen, or a query cache | Network: no identical requests in a row | -| Request per keystroke | Debounce, cancel the previous request, one constant for the delay | Type fast: one request | -| Unbounded lists from the API | Page or cursor plus a limit, a "has more" flag | One page per request | -| Sequential independent calls | Run them in parallel, keep dependent ones ordered | Network: requests start together | -| Text responses uncompressed | Brotli with Gzip as fallback; skip already-compressed types | `content-encoding` header | -| Static files without cache policy | Long `immutable` cache for hashed names, short for HTML | Second load served from cache | -| Static files from the app server | CDN prefix in one setting | Network: CDN origin | -| Query inside a loop (N+1) | Join or eager loading | Query count does not grow with the list | -| Full table scans | Index for the frequent `WHERE`/`JOIN`/`ORDER BY`, migration | `EXPLAIN` uses the index | -| Whole rows where two fields are needed | Select the columns | Query log names them | -| Connection per request | Pool with a maximum and a wait timeout | Open connections stay bounded | -| External calls without a timeout | Timeout plus bounded retries, defined user-facing error | Point at a slow host: it aborts | -| Slow work inside the request | Background job, immediate "accepted" with a status | Request returns at once, result arrives | -| UI waiting on the server | Optimistic update with rollback; never for payments | Click is instant, error reverts | -| Repeated reads of static data | Cache with a named key and a TTL, invalidate on write | Second read misses the database | -| No visibility | OpenTelemetry traces, Core Web Vitals from real users | Slow request visible in the trace | +| # | Symptom | Fix | Verify with | +| --- | --- | --- | --- | +| 1 | Blank area or spinner while data loads | Skeleton shaped like the coming content; errors rendered apart | Throttled network: the shape appears | +| 2 | Heavy images | WebP and AVIF, original as fallback, explicit dimensions | Network: modern type, no layout shift | +| 3 | Same API call repeated | One call per screen, or a query cache | Network: no identical requests in a row | +| 4 | Request per keystroke | Debounce, cancel the previous request, delay in one constant | Type fast: one request | +| 5 | Unbounded lists from the API | Page or cursor plus a limit, a has-more flag | One page per request | +| 6 | Static files served by the app server | CDN prefix in one build or hosting setting | Network: CDN origin | +| 7 | Slow work inside the request | Background queue, immediate accepted status, result visible | Request returns at once | +| 8 | Query inside a list loop (N+1) | Join or eager loading | Query count does not grow with the list | +| 9 | Text responses uncompressed | Brotli with Gzip fallback; skip already-compressed types | `content-encoding` header | +| 10 | Same static data read from the database | Redis cache with a named key and TTL, invalidate on write | Second read misses the database | +| 11 | Dependencies imported nowhere | `depcheck`/`knip`, remove after my ok, update the lock file | Build, tests and start still pass | +| 12 | External calls without a timeout | Timeout plus bounded retries, defined user-facing error | Point at a slow host: it aborts | +| 13 | Model answer arrives as one block | Stream tokens, handle cancel and mid-stream error | Text appears in pieces | +| 14 | Interface waits for the server | Optimistic update with rollback; never for payments | Click is instant, error reverts | +| 15 | Offscreen images load at first paint | `loading="lazy"` for those only, dimensions set | First paint fetches fewer requests | +| 16 | Independent calls run one after another | Parallel execution, dependent ones stay ordered | Requests start together | +| 17 | Full table scans | Index for the frequent `WHERE`/`JOIN`/`ORDER BY`, migration | `EXPLAIN` uses the index | +| 18 | No visibility into slow requests | OpenTelemetry traces, no personal data or secrets | Trace shows each call's time | +| 19 | App and database in different regions | Co-locate them, ask before moving anything | Latency measured before and after | +| 20 | Content drawn only in the browser | Server render or build-time generation | View source contains the text | +| 21 | Third-party scripts block the page | `defer`/`async`, or load after first interaction | Page works without them | +| 22 | One bundle for every page | Split by route, dynamic import for editors, charts, maps | Per-page file, build report | +| 23 | Long lists render every row | Virtualize; keep scroll, search and keyboard focus | DOM holds only visible rows | +| 24 | Whole rows fetched for two fields | Select the columns, heavy fields only where used | Query log names them | +| 25 | New connection per query | Pool with a maximum and wait timeout, pooler for serverless | Open connections stay bounded | +| 26 | Rerenders without a data change | Targeted memoization, state closer to use, split context | Profiler shows no extra rerenders | +| 27 | Static files without a cache policy | `immutable` for hashed names, short or revalidated HTML | Second load served from cache | +| 28 | State kept in process memory | Move sessions, uploads and cache out, then scale | Two instances share one session | +| 29 | Fonts from a third party | Self-hosted woff2, only used weights, `font-display` | Fonts come from your origin | +| 30 | No real-user numbers | Core Web Vitals plus browser errors into a dashboard | Metrics arrive after a visit | +| 31 | Behaviour on weak devices unknown | Throttled network and CPU profile, report by scenario | Report names pages and causes | -## Do not +Rows 1 to 31 match the numbered recipes in [`references/prompts.md`](references/prompts.md). Read the recipe when the table row is not specific enough; each one ends with its own check. -- Add memoization everywhere. Only where a profile shows the rerender. -- Change infrastructure, regions, replicas, or a paid service without asking first. -- Ship a perf change without the before and after number. +## Traps -## Full recipes +- Lazy-loading the largest image on the first screen. It is usually the LCP element; keep it eager and preloaded. +- Memoization applied everywhere after one slow profile. It hides the cause and adds its own cost. +- A cache without invalidation. The page gets fast and wrong. +- Prefetching everything. The user downloads pages they never open. +- Optimistic updates on money, permissions or anything irreversible. +- Measuring on localhost, or after warming the cache. Both hide the problem you were asked to fix. +- Reporting "faster" with no number, or with a different instrument than the one used before. -[`references/prompts.md`](references/prompts.md) holds 31 recipes, one per topic above. Read the numbered section that matches the symptom: the wording is more specific than this table, and each recipe ends with its own check. +## Do not -Take one recipe per slice. Run its check. If the recipe does not fit this stack, say so and change nothing. +- Change infrastructure, regions, replicas, or a paid service without asking first. +- Touch several topics in one slice. One row, one fix, one measurement. +- Ship a perf change without the before and after number.