# 性能优化 (performance-optimization)

> 按测量、定位、修复、验证、防护五步优化前端、后端和数据库性能，只保留经测量证明有效的改动。

- 分类: [性能优化](https://www.myskills.tools/zh/categories/performance/)
- 来源: 社区 · Addy Osmani
- 代码仓库: https://github.com/addyosmani/agent-skills/tree/main/skills/performance-optimization (commit ee3e850)
- SKILL.md: https://github.com/addyosmani/agent-skills/blob/main/skills/performance-optimization/SKILL.md
- 安装命令: `npx skills add addyosmani/agent-skills --skill performance-optimization`
- 许可证: MIT
- 兼容工具: Claude Code, Codex, Cursor, Copilot, Gemini CLI
- 权限: read-repo ✓, write-files ✓, shell ✓, network ✗
- 状态: 扫描通过
- 规则扫描无法覆盖所有风险，安装前请阅读此技能的 SKILL.md，确认权限后再使用。

## 核心规则

先测量再优化，只保留经复测证明有效的改动，没有效果的改动一律回退。

## 执行阶段

1. **测量基线** — 结合合成测试（Lighthouse、DevTools）和真实用户数据（web-vitals、CrUX）建立基线，并根据症状决定先测什么。
2. **定位瓶颈** — 把症状对应到可能原因，如 N+1 查询、缺失索引、包体过大或主线程长任务。
3. **修复单一瓶颈** — 只修复上一步找到的问题，参照 N+1、分页、EXPLAIN ANALYZE、缓存、图片和包体等模式。
4. **复测并取舍** — 以相同条件复测并与运行间波动比较，超过阈值且测试通过才保留，否则回退；所有尝试都记入台账。
5. **防止回归** — 针对用户可感知的指标，加上 CI 合成预算（bundlesize、Lighthouse CI）和线上监控。

## 权限说明（据 SKILL.md 整理）

| 能力 | 是否需要 | 说明 |
|---|---|---|
| 文件写入 | 需要 | 修改应用代码、查询和配置，并在 PERF.md 或 PR 描述中记录尝试。 |
| 命令执行 | 需要 | 运行测量与测试命令，如 Lighthouse CI、bundlesize、EXPLAIN ANALYZE 和测试套件。 |
| 网络外发 | 不需要 | 技能未要求调用外部服务，测量针对你自己的应用。 |

## SKILL.md 头部信息（YAML）

```yaml
---
name: performance-optimization
description: 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.
---
```

首页: https://www.myskills.tools/zh/ · URL: https://www.myskills.tools/zh/skills/performance-optimization/
