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 skills add pingfanfan/hello-dsh --skill perf-optimizegit clone --depth 1 https://github.com/pingfanfan/hello-dshWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/pingfanfan/hello-dsh/perf-optimize)<a href="https://agentmods.dev/skills/pingfanfan/hello-dsh/perf-optimize"><img src="https://agentmods.dev/badge/skills/pingfanfan/hello-dsh/perf-optimize/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/pingfanfan/hello-dsh/perf-optimize"><img src="https://agentmods.dev/badge/skills/pingfanfan/hello-dsh/perf-optimize.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector pass
What 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.1 | $0.00044 | $0.01035 |
| Opus 5.5 | $0.00018 | $0.00414 |
| Sonnet 5.5 | $0.00009 | $0.00207 |
| Haiku 4.5 | $0.00004 | $0.00103 |
Grade A, and why
perf-optimize 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 3mo 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.
What it actually says
性能优化
没有测量就不要优化。 人对性能瓶颈的直觉准确率极低,凭猜优化的结果通常是把代码改复杂了,而慢的地方没动。
顺序
一、确定目标
先回答:多快算够?
「让它更快」不是目标。「首屏在 3G 下 2 秒内可交互」「这个接口 p99 低于 200ms」才是。
没有目标就不知道什么时候该停,容易在收益递减的地方一直花时间。
二、测量
拿到真实数据,不是感觉:
- 用 profiler 找热点,不要读代码猜
- 测真实场景:真实数据量、真实并发、生产配置
- 记录基线数字,写下来
常见的测量陷阱:
- 在开发模式下测(有 source map、有热重载、没压缩)
- 用小数据集测(
n=10时 O(n²) 和 O(n) 没区别) - 只测一次(要多跑几次看方差)
- 测的是冷启动但线上是热的(反之亦然)
三、找到真正的瓶颈
profiler 给出热点后,先分类:
| 类型 | 典型表现 | 方向 |
|---|---|---|
| 算法复杂度 | 数据量翻倍时间翻四倍 | 换算法/数据结构 |
| N+1 | 大量重复的小查询/小请求 | 批量化 |
| 重复计算 | 同一个结果算很多遍 | 缓存或提升 |
| 阻塞 | CPU 空闲但很慢 | 并发化、异步化 |
| 过度渲染/序列化 | 时间花在框架内部 | 减少无效更新 |
先看复杂度和 N+1。 这两类的收益通常是数量级的,而微优化只有百分之几。
四、改一个,再测
一次只改一处,改完立刻测。攒着一起改的话,你不知道哪个起了作用,也可能某个改动其实是负优化。
记录每次的数字,形成对照。
五、确认没改坏
性能优化最容易引入正确性 bug,因为它常常涉及缓存、并发、跳过某些步骤。优化后必须跑完整测试,尤其是边界情况。
值不值得做
在动手前问:
- 这个路径被执行多少次? 一天调一次的地方省 50ms 毫无意义
- 优化后代码复杂多少? 复杂度是永久成本,性能收益可能是一次性的
- 有没有更简单的办法? 加个索引、调个配置、换个参数,往往比重写代码有效
最快的代码是不执行的代码。 优化之前先问:这一步能不能干脆不做?能不能延后到真正需要时?能不能只处理用户实际看到的那部分?
缓存的代价
缓存是最常用也最容易出问题的手段。加之前想清楚:
- 什么时候失效? 想不清楚就不要加
- 失效错了会怎样? 展示旧数据的后果能接受吗
- 命中率会是多少? 命中率低的缓存是纯开销
- 占多少内存? 无上限的缓存等于内存泄漏
一个真实案例的形态
DSH 有过一个性能问题:TokenMeter 在每个会话事件后重建完整快照,导致二次方级退化。
这个形态很典型:单次操作看起来很便宜,但它被放在了一个会重复 N 次的位置上,且每次都处理全量数据。 找这类问题的方法是看「循环里有没有全量操作」,而不是看单个函数快不快。
不要做的事
- 不要在没有 profiler 数据的情况下动手
- 不要优化不在热路径上的代码
- 不要为了性能牺牲正确性
- 不要用微基准测试的结论推断真实场景
- 不要一次改多处
- 不要在没有目标数字的情况下无限优化
- 不要忘了记录基线,否则无法证明有改进
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.
- 3mo ago First seen · 92 lines · 44 tokens per session scan A c47accbb430b
perf-optimize is a skill published in the GitHub repository pingfanfan/hello-dsh (111 stars, last pushed 2mo ago), licensed MIT. It adds 44 tokens to every session and 1,035 once invoked, about $0.0002 per session on Opus 5.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-30.
perf-optimize compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| perf-optimizepingfanfan/hello-dsh | Skill | 111 | 2mo ago | MIT | A | 44 | Claude Code, Codex |
| dsh-plugin-guidePerryLink/dsh-plugin-guide | Skill | 74 | 3d ago | Apache-2.0 | A | 62 | Claude Code, Codex |
| diagnosing-bugs-zhgongyijie85/mattpocock-skills-dsh-zh | Skill | 8 | 16d ago | MIT | A | 48 | Claude Code, Codex |
| systematic-debuggingamplifthq/oh-my-dsh | Skill | 20 | 1mo ago | MIT | A | 15 | Claude Code, Codex |
| dsh-debug-sessionhackerFish/awesome-dsh-skills | Skill | 6 | 3mo ago | MIT | A | 40 | Claude Code, Codex |
| dsh-ci-test-reliabilityWZZNNE/DSH-CyberWorkStation | Skill | 26 | 2mo ago | none | A | 83 | Claude Code, Codex |
| dsh-speed-up-perfWZZNNE/DSH-CyberWorkStation | Skill | 26 | 2mo ago | none | A | 45 | Claude Code, Codex |