agentleFS
KhaledSaeed18KhaledSaeed18/dotclaude/skills/engineering/performance-optimization/SKILL.md

performance-optimization

Skill5 starsChanged 5 months agoMITView on GitHub

Fix a performance problem by profiling first, making one targeted change, and verifying both the speedup and that correctness held. Use when a feature is measurably slow, a page or API exceeds its budget, or a query takes too long. Do not use to pre-optimize code that has not been measured.

83 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use constraint-driven-development, using-agent-skills and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • vinvcnSkill

    constraint-driven-development

    把一个项目的质量线确立为书面契约,并阻止 agent 悄悄降低它。通过访谈确定用户在意哪些维度,当用户心里没有数字时提供合理的默认阈值,把一切记录进 CONSTRAINTS.md,并盯住 diff 中质量线被削弱的迹象——新增的 @ts-ignore 或 eslint-disable 抑制注释、被跳过或删除的测试、被剥掉的断言、未实现的 stub、被调低的阈值。当没有任何质量线被写下来时使用;当用户说 "set up constraints" 或 "define our standards" 时;当用户希望把他们在意的维度——无障碍性、Web 性能、覆盖率——设置成被强制执行的约束时;当 agent 为了变绿不断静默检查或跳过测试时;当你需要一个覆盖率或性能阈值却不知道该选什么数字时;或者当 agent 写下的代码超出任何人会读的体量时。

    Also in 4 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 21 projects that use this

  • LLl0k0laDSkill

    git-workflow-and-versioning

    Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

    Also in 23 projects that use this

  • borhen68Skill

    observability-and-instrumentation

    Instruments code so production behavior is visible and diagnosable. Use when adding logging, metrics, tracing, or alerting. Use when shipping any feature that runs in production and you need evidence it works. Use when production issues are reported but you can't tell what happened from the available data.

    Also in 12 projects that use this

  • az9713Skill

    deprecation-and-migration

    Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when deciding whether to maintain or sunset existing code.

    Also in 21 projects that use this

  • az9713Skill

    code-simplification

    Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

    Also in 29 projects that use this

  • +6 more from LLl0k0laD

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 9 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 72 edited versions we read keep these.

  • 9

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run the scenario and record the baseline:

    line 20
  2. Distinctive:

    Read the profiler output - do not guess from the source.

    line 40
  3. Distinctive:

    Add caching everywhere in case something else is also slow

    line 66
  4. Distinctive:

    Run the same scenario under the same conditions as the baseline:

    line 73
  5. Distinctive:

    If the improvement is less than 20% or does not meet the target, re-profile - you may have fixed a symptom, or the bottleneck may have …

    line 79
  6. Distinctive:

    Do not add caching without a cache invalidation strategy.

    line 93
  7. Distinctive:

    Do not replace a correct algorithm with a faster but subtly incorrect one and call it "good enough."

    line 94
  8. Distinctive:

    Do not optimize code that is called rarely - focus on hot paths only.

    line 95
  9. Distinctive:

    Do not report the optimization as complete before running both the performance measurement and the correctness check.

    line 96

“Common” is measured: kept by at least 6 in 10 of the 72 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Profile first. Every performance intuition is wrong until the profiler confirms it. The code that looks slow is rarely the bottleneck; the bottleneck is almost always somewhere the code looks unremarkable. An optimization without a measurement is a guess. A guess that happens to speed things up does not mean you found the right thing.

The one rule

No change before you have a baseline measurement and a profiled bottleneck. If you cannot name the specific file, function, and line where the most time or memory is spent - with numbers - you are still in the investigation phase.

Step 1: Establish the baseline

Define what "slow" means in terms the problem must satisfy:

  • What is the current measured value? (response time, frame rate, memory usage, query duration, build time)
  • What is the target? (a budget from a spec, a regression from a previous version, a user-reported threshold)
  • Can the scenario be reproduced reliably? If not, instrument first and gather data before optimizing.

Run the scenario and record the baseline:

# For Node.js / server-side
node --prof app.js           # then: node --prof-process isolate-*.log
# or: clinic flame -- node app.js

# For queries
EXPLAIN ANALYZE SELECT ...   # PostgreSQL
# or the equivalent for your database

# For browser / frontend
# Use the browser devtools Performance panel; record the scenario end-to-end
# Look at the flame chart, not just the summary

Save the baseline number. The optimization is only valid if the after-measurement is better than this.

Step 2: Find the bottleneck

Read the profiler output - do not guess from the source. Identify:

  • The hot function: the one frame where the most CPU time is spent (not called the most - spent the most)
  • The call chain: how does execution reach the hot function? What is the logical operation that triggers it?
  • The bottleneck class: is this CPU-bound (computation), memory-bound (allocation/GC pressure), I/O-bound (disk or network latency), lock-bound (contention), or rendering-bound (layout/paint)?

Common bottlenecks that do not look like bottlenecks:

  • N+1 queries: a loop that runs one query per item instead of one query for all items
  • Serialization on the hot path: JSON.parse / JSON.stringify inside a tight loop
  • Synchronous I/O blocking an event loop
  • Repeated computation of a value that never changes within the call
  • An O(n^2) algorithm that looks like two nested loops over a "small" list that grew
  • Memory allocation creating GC pressure (allocating objects in tight loops, large closures held alive)

Step 3: Form a hypothesis

State it exactly: "The bottleneck is X at file:line because Y, which will be fixed by Z."

Be specific enough to be falsifiable. "The code is slow because it does too much" is not a hypothesis. "The getUser function issues one SQL query per item in the results array at src/db/users.ts:44, so a page with 50 results makes 50 database round trips; replacing this with a single WHERE id IN (...) query should reduce the query time from ~500ms to ~10ms" is a hypothesis.

Step 4: Make one change

Address only the identified bottleneck. Do not:

  • Refactor surrounding code while fixing performance
  • Add caching everywhere in case something else is also slow
  • Change the algorithm and the data structure at the same time

The change should be the minimum needed to fix the specific bottleneck. Multiple simultaneous changes make the measurement impossible to attribute.

Step 5: Measure and compare

Run the same scenario under the same conditions as the baseline:

  • Record the after measurement using the same tool and methodology
  • Calculate the delta: how much faster, how many fewer allocations, what query time
  • State whether the target is now met

If the improvement is less than 20% or does not meet the target, re-profile - you may have fixed a symptom, or the bottleneck may have shifted to a new location now that the first one is gone.

Step 6: Verify correctness

An optimization that breaks behavior is not an optimization - it is a bug. Run the full test suite. If there are no tests covering the modified path, write one before treating the optimization as done.

Check specifically:

  • Does the output still match the baseline for all inputs, including edge cases?
  • Are any caches invalidated correctly? Does a cache hit return the same result as a cache miss?
  • Does the optimized code handle concurrent access correctly if the original did?

What not to do

  • Do not add caching without a cache invalidation strategy.
  • Do not replace a correct algorithm with a faster but subtly incorrect one and call it "good enough."
  • Do not optimize code that is called rarely - focus on hot paths only.
  • Do not report the optimization as complete before running both the performance measurement and the correctness check.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.