perf-optimize

perf-optimize is a skill for Claude Code, Codex from pingfanfan/hello-dsh. It costs 44 tokens per session (1,035 once invoked), scanned A, original, MIT.

A performance-improvement guide that requires measuring real behaviour before changing code. It explains how to identify bottlenecks, test one change at a time, and check that the change did not break anything.

In plain words
What is it for?
Use it to set measurable speed targets, profile applications, investigate repeated queries or calculations, compare optimization results, and assess whether an optimization is worth its maintenance cost.
Why use it?
It prevents guesswork and avoids making code more complicated without improving the part that is actually slow.

Skill for Claude CodeCodex

Install

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.

agentmods
npx agentmods add skills/pingfanfan/hello-dsh/perf-optimize
Any agent
npx skills add pingfanfan/hello-dsh --skill perf-optimize
Clone the repo
git clone --depth 1 https://github.com/pingfanfan/hello-dsh

Made for: Claude Code, Codex.

Wrote 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.

agentmods badge for perf-optimize

README.md
[![agentmods](https://agentmods.dev/badge/skills/pingfanfan/hello-dsh/perf-optimize.svg)](https://agentmods.dev/skills/pingfanfan/hello-dsh/perf-optimize)
Your own site
<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>
Per session 44 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,035 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce 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

Measured 4d ago against content hash c47accbb430b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

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.

examples/skills/perf-optimize/SKILL.md · 92 lines

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 数据的情况下动手
  • 不要优化不在热路径上的代码
  • 不要为了性能牺牲正确性
  • 不要用微基准测试的结论推断真实场景
  • 不要一次改多处
  • 不要在没有目标数字的情况下无限优化
  • 不要忘了记录基线,否则无法证明有改进
Changes

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.

  1. 4d ago First seen · 92 lines · 44 tokens per session scan A c47accbb430b

Subscribe to this mod's changes

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.

Related

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…

PerryLink/dsh-plugin-guide · 76 tokens

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…

zhu1090093659/dsh-web · 151 tokens

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…

zhu1090093659/dsh-web · 123 tokens

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…

zhu1090093659/dsh-web · 120 tokens

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.

zhu1090093659/dsh-web · 45 tokens

dsh-web-documentation

Use when adding or editing dsh-web README files, docs, AGENTS.md instructions, user-facing configuration text, or bilingual documentation pairs.

zhu1090093659/dsh-web · 34 tokens