Skip to content
Development
Skill

/performance-optimization

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

From plugin
dotclaude
586 skills1 agent1 command

Claude Code

$ npx -y skills add KhaledSaeed18/dotclaude --skill performance-optimization --agent claude-code

SKILL.md

performance-optimization.SKILL.md
name: performance-optimization
description: 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.

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.
Read more
@khaledsaeed18
Ships withdotclaude

Reusable Claude Code extension registry. skills, subagents, slash commands, and hooks for engineering, git, testing, and security workflows. Distributed as a shadcn GitHub registry and as installable plugins.

586 skills1 agent
Get the whole plugin

Stars on GitHub

Momentum

stars in total
5
Star history of KhaledSaeed18/dotclaude on GitHub, a chart by star-history.com

Other skills on dotclaude.

academic-writing

academic-writing

Write or revise thesis and paper prose section by section (abstract, introduction, related work, method, results, discussion,…

bibtex-manager

bibtex-manager

Maintain the thesis .bib file as a single source of truth: fetch verified BibTeX from a DOI, arXiv id, or title via CrossRef and…

citation-graph

citation-graph

Expand a set of key papers into the literature around them by walking the citation graph with the Semantic Scholar and OpenAlex…

citation-verifier

citation-verifier

Audit every citation in a chapter, paper, or proposal against the .bib file and the real world: each cite key must exist, each…

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills10d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc12d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react1d252k
@facebook@facebookInstall Skill

Questions about performance-optimization.

Which coding agents can use performance-optimization?
performance-optimization installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.