performance-optimization
Optimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.
1实现原理 · 为什么它能做到
实施严格的五步性能优化循环(MEASURE → IDENTIFY → FIX → VERIFY → GUARD),坚持必须先基于基线测量找出真实瓶颈,禁止任何无测量凭据的过早微优化。
Measure before optimizing. Performance work without measurement is guessing — and guessing leads to premature optimization that adds complexity without improving what matters. Profile first, identify the actual bottleneck, fix it, measure again.
前端测量结合合成监控(Synthetic / Lighthouse / DevTools)与真实用户监控(RUM / web-vitals / CrUX)双轨数据,覆盖 LCP/INP/CLS 等 Core Web Vitals 指标。
- **Synthetic (Lighthouse, DevTools Performance tab):** Controlled conditions, reproducible. … - **RUM (web-vitals library, CrUX):** Real user data in real conditions.
通过清晰的症状分流决策树(Where to Start Measuring)从页面首屏加载、交互卡顿、路由切换与后端接口四个方向快速指引排查路径。
What is slow? … First page load … Large bundle? --> Measure bundle size, check code splitting … Slow server response? --> Measure TTFB in DevTools Network waterfall
后端针对常见反模式提供定向方案:根治 N+1 查询、全表无界抓取强制分页,以及通过 EXPLAIN ANALYZE 读取执行计划按查询形状建立复合索引。
- **N+1 queries.** One query per row is the most common backend bottleneck. Fetch the relation in the same query (join/include) instead of in the loop.
明确连接池耗尽排查原则与容量上限:单进程连接池须保证实例数乘最大连接数不超出数据库承载上限,禁止用无脑调大连接池掩盖连接泄漏。
- **Connection pool exhaustion.** Signature: *every* endpoint slows at once, time is spent waiting for a connection rather than executing, and the database shows mostly idle sessions.
构建严谨的缓存设计与防击穿防穿透纪律:要求显式指定失效策略、缓存键必须包含所有影响响应的输入(租户/语言/权限),并加设并发合并或陈旧响应守卫。
- **Missing caching.** Cache what is expensive to produce and read far more often than it changes … Every input that changes the response belongs in the key … Guard hot keys against the stampede
前端深度优化图片与资源加载:给所有图片显式标注宽高消除 CLS,LCP 图片配置高优先级加载与多分辨率响应式格式,非首屏图片懒加载。
- **Missing image optimization.** Every image declares `width` and `height` (CLS). The LCP image gets `fetchpriority="high"`, modern formats (AVIF, WebP) through `<picture>`
实行绝对严苛的验证裁决法则:复测必须采用与基线完全一致的环境与命令,收益在波动噪声内(中性结果)必须强制回滚,杜绝积累无效复杂度。
**"Neutral" is a revert, not a keep.** This is the step teams skip: the change is already written, throwing it away feels wasteful, so it lands unmeasured, and the codebase accretes complexity that never bought anything.
2核心能力
4管控建议与判定依据
5第二遍独立确认
- [ok] 自身目录无自带可执行脚本与外发网络调用 — 经检查,skills/performance-optimization/ 下仅有 SKILL.md 与 references/optimization-patterns.md,全量扫描无网络请求、无凭证读取、无自带 .sh/.js 脚本。
- [ok] CI 命令仅为工程建议与示例,非 skill 自身打包执行 — 扫描命中的 npx bundlesize 与 npx --package=@lhci/cli lhci autorun 处于 Step 5 Enforce in CI 代码块中,属于推荐用户在工程 CI 流水线中集成的配置示例,skill 自身不带执行钩子。
- [ok] Core Web Vitals 规范阈值定义真实准确 — SKILL.md 中明确给出 LCP (≤2.5s)、INP (≤200ms)、CLS (≤0.1) 的 Good 级别标准,与 Google 官方 CWV 规范完全一致。
- [ok] optimization-patterns.md 完整涵盖声明的 6 种优化反模式 — references/optimization-patterns.md 包含 N+1 Queries、Unbounded Data Fetching、Queries That Ignore Their Index、Connection Pool Exhaustion、Missing Image Optimization、Unnecessary Re-renders、Large Bundle Size、Missing Caching 等全部对应模式与代码实现。
- [ok] 验证与回滚纪律(Keep or Revert 矩阵)有据可循 — SKILL.md Step 4 明确提供 Result vs. baseline 裁决矩阵以及 Neutral is a revert 原则,并要求建立实验台账。
6结论
Preview this skill in an interactive chat playground. Generic LLM evaluation trial.
💬 Open Chat Trial (Preview)