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/pingfanfan/hello-dsh/perf-optimizenpx 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.svg" alt="Measured on agentmods" height="20"></a>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 | $0.00044 | $0.01035 |
| Opus 5 | $0.00022 | $0.00517 |
| Sonnet 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 4d 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.
- 4d 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 (87 stars, last pushed 21d ago), licensed MIT. It adds 44 tokens to every session and 1,035 once invoked, about $0.0002 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-30.
Other skills, from other repositories
dsh-plugin-guide
Use when developing, reviewing, packaging, debugging, or answering questions about DeepSeek Harness (DSH) plugins — the plugin-based agent harness on vendored Cordis. Applies the official plugin-development constraints (plugin contract, cordis.yml layers, services/events/effects, tool DSL, bundles/profiles) backed by…
dsh-web-release
Release and publish the dsh-web monorepo (DSH Web GUI plugin family + skin collection) — bump all packages to one unified version, commit and tag (tags are cut from main after dev integration; dev is the integration branch), push the vX.Y.Z tag that triggers the GitHub Actions publish pipeline, and verify the npm…
dsh-web-community-plugin-developer
Develop a DSH community plugin and register it in the dsh-web Community Plugins index — author the plugin in the contributor's own repository following the official cordis bundle standard, add its entry to packages/dsh-community-plugins/community.json, regenerate the index with scripts/community-index, rebuild and…
dsh-web-skin-developer
Build a new skin for the dsh-web skin collection (DSH Web GUI) and publish it into the Skin Center — the first-level settings section — scaffold with scripts/dsh-skin-new, author the v2 skin.json manifest plus skin.css token remap (pure asset directory, no package.json, no build step), validate with scripts/dsh-skin…
dsh-web-pre-push-checks
Use before pushing, opening or updating a pull request, or claiming dsh-web checks pass. Selects the required repository gates and diff-specific generation, build, and GUI evidence.
dsh-web-documentation
Use when adding or editing dsh-web README files, docs, AGENTS.md instructions, user-facing configuration text, or bilingual documentation pairs.