Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/wade-devcode/awesome-coding-skills-cn/performance-profilingnpx skills add Wade-DevCode/awesome-coding-skills-cn --skill performance-profilinggit clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cnWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00021 | $0.02302 |
| Opus 5 | $0.00010 | $0.01151 |
| Sonnet 5 | $0.00004 | $0.00460 |
| Haiku 4.5 | $0.00002 | $0.00230 |
Grade A, and why
performance-profiling scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 157 lines — stays where its author put it; the contents beside it link to each section on GitHub.
性能调优
何时用
- 系统出现明显变慢、延迟升高、资源使用异常时。
- 接到"优化这段代码"的任务,准备动手之前。
- 发现自己想"感觉这里可以缓存一下"但没有数据支撑时——这是需要先测量的信号。
- 在 code review 里看到未经测量的性能优化改动时。
核心规则
1. 先测量:用 profiler/benchmark 找真实瓶颈,不靠猜
规则: 任何优化动作之前,必须先用工具(profiler、benchmark、APM 追踪)找出真实的热点函数或慢路径,再决定优化什么。
为什么: AI 在"优化性能"任务中常先凭直觉下手:把字典查找换成数组遍历"因为听说数组快"、把 for 循环改成列表推导"因为更 Pythonic"。但实际瓶颈往往在完全不同的地方——90% 的时间花在一个数据库查询上,而 AI 在优化内存里的字符串拼接。没有数据的优化不仅收益不明,还可能引入新 bug 或降低可读性。
怎么做:
- Python 用
cProfile/py-spy,Node.js 用--prof或 Chrome DevTools,Go 用pprof。 - APM(Datadog、New Relic、Sentry)看生产慢请求的 trace,定位到具体函数调用。
- 先得到一份"热点函数列表"(火焰图或 top-N),再决定优化哪里。
2. 优化热点,不过早优化冷路径;有数据支撑再改
规则: 只优化 profiler 确认的高频/高耗时路径,忽略执行频率低的冷路径;每次优化决策都要有性能数据作为依据。
为什么: AI 在生成代码时常做"预防性优化"——在一个每天调用 10 次的管理接口里用位运算替代普通算术,因为"更高效"。这些优化降低了代码可读性,却对实际用户体验毫无影响。真实的性能收益来自于优化那些每秒调用上千次或每次耗时数百毫秒的路径,而不是散落各处的"感觉更快"的改写。
怎么做:
- 只处理 profiler 报告中占总耗时前 80% 的函数。
- 改之前记录基准数字(当前 P99 延迟、QPS 上限、内存峰值)。
- 对于冷路径,优先选择可读性好的实现,留注释说明"此处不是瓶颈,无需优化"。
3. 关注算法复杂度与 I/O(N+1、同步阻塞、无缓存),常比微优化收益大
规则: 先检查 O(n²) 算法、N+1 查询、同步阻塞 I/O、无缓存的重复计算这类结构性问题,再考虑微观层面的优化。
为什么: AI 进行性能优化时容易去做微优化(内联函数、减少对象分配、换更快的序列化库),却忽视结构性问题。常见事故:一个列表页接口产生 N+1 查询——每条记录触发一次独立 DB 查询,100 条记录 = 101 次查询。把 JSON 序列化从 json 换成 orjson 节省了 1ms,但 N+1 查询吃掉了 500ms。结构性优化(改成一次 JOIN 查询)的收益是微优化的 100 倍。
怎么做:
- 用数据库慢查询日志或
EXPLAIN检查是否有 N+1、缺失索引、全表扫描。 - 检查热路径上是否有阻塞 I/O 可以改为异步或批量处理。
- 检查计算密集型结果是否有合适的缓存层(内存缓存/Redis),减少重复计算。
- 对循环内的数据库查询、HTTP 调用保持警惕。
4. 改完再测量对比,确认真变快且没破坏正确性
规则: 优化完成后必须重新运行 benchmark/profiler,与基准数字对比,确认性能确实提升;同时运行测试套件确认正确性没有回归。
为什么: AI 实施优化后常缺失验证步骤——直接提交,相信"理论上更快"。实际中常见结果:优化后 benchmark 数字基本没变(瓶颈在别处),或者"优化"引入了竞态条件、缓存不一致、精度损失等正确性问题。没有前后对比数字的优化 PR 无法让 reviewer 判断是否值得合并。
怎么做:
- 固定测试环境(同一机器、同一数据量、预热后再测)保证对比公平。
- 同时记录优化前后的延迟(P50/P95/P99)和吞吐量,不只看平均值。
- 运行完整测试套件,包括边界用例和并发测试。
- 在 PR 描述里贴出"优化前 vs 优化后"的数字对比。
5. 记录基准与取舍,避免可读性为微小收益让路
规则: 性能优化产生的代码复杂度提升,必须伴随明确的数字收益记录;若收益小于可读性代价,优先选择清晰实现。
为什么: AI 做性能优化时常引入晦涩写法——位运算替代乘除、手动内联展开循环、复杂的预分配逻辑——并声称"性能更好"。但没有记录收益是多少,也没有说明这段复杂代码将来是否还需要人工维护。三个月后下一个维护者看到这段代码完全不懂,但也不敢改,因为不知道它到底优化了什么、优化幅度多大。
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 157 lines · 21 tokens per session scan A 9d2e4f92e678
performance-profiling is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (6 stars, last pushed 2mo ago), licensed MIT. It adds 21 tokens to every session and 2,302 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
chinese-git-workflow
国内 Git 平台配置参考——Gitee、Coding.net、极狐 GitLab、CNB 的 SSH/HTTPS/凭据/CI 接入差异与镜像同步配置。仅在用户显式 /chinese-git-workflow 时调用,不要根据上下文自动触发。.
brainstorming
在任何创造性工作之前必须使用此技能——创建功能、构建组件、添加功能或修改行为。在实现之前先探索用户意图、需求和设计。.
chinese-code-review
中文 review 沟通参考——话术模板、分级标注(必须修复/建议修改/仅供参考)、国内团队常见反模式应对。仅在用户显式 /chinese-code-review 时调用,不要根据上下文自动触发。.
chinese-commit-conventions
中文 commit 与 changelog 配置参考——Conventional Commits 中文适配、commitlint/husky/commitizen 中文模板、conventional-changelog 中文配置。仅在用户显式 /chinese-commit-conventions 时调用,不要根据上下文自动触发。.
chinese-documentation
中文文档排版参考——中英文空格、全半角标点、术语保留、链接格式、中文文案排版指北约定。仅在用户显式 /chinese-documentation 时调用,不要根据上下文自动触发。.
systematic-debugging
Skill "systematic-debugging" from jnMetaCode/superpowers-zh, covering 系统化调试, 概述, 铁律, 何时使用 and 四个阶段.