ryanthedev/code-foundations/performance-optimization
Claude Code and agent skill by ryanthedev/code-foundations
- community
Checking that the SKILL.md file is still in the repository.
Applies measure-first performance optimization: profiles to find hot spots, applies algorithm and data-structure improvements before micro-optimizations, and validates each change prevents regression. For single-process code tuning; not for correctness bugs (use cc-debugging) or concurrency, distributed, and real-time tuning (explicitly out of scope).
Install
npx vskill@latest install ryanthedev/code-foundations/performance-optimizationSKILL.md
Skill: performance-optimization
Measure First — the gate every optimization passes through
Profile before optimizing — intuition about hot spots is measurably wrong more often than right:
- Correctness before speed -- make it work, then make it fast
- <4% of code causes >50% of runtime (Knuth 1971) -- find the hot spot before touching anything
- >50% of optimizations produce negligible or negative results (CC p.607) -- measurement prevents wasted effort
- I/O costs ~1000x a memory access (CC p.591) -- batch it and keep it out of tight loops
Optimization proceeds only from a measurement — unmeasured "optimizations" are edits with a coin-flip chance of helping.
Scope Limitations
This skill covers single-threaded, single-process code tuning for general-purpose computing.
Not covered (need specialized guidance):
- Concurrency: Lock contention often dominates; profile thread states, not just CPU
- Distributed systems: Network latency ~10,000x memory; optimize RPC/serialization first
- Real-time systems: Need worst-case latency, not average; caching adds variance
- Embedded/constrained: Memory/power budgets require different tradeoffs
The Simplicity-Performance Relationship
Simpler code usually runs faster. Fewer special cases = less code to check; deep modules = more work per call with fewer layer crossings; complicated code does extraneous or redundant work.
Primary Workflow: 7-Step Decision Tree
Each step is a gate — skipping one forfeits the evidence the next step depends on.
Step 2 Detail: Measurement
What counts as valid measurement:
- Actual profiling data (timing, call counts, memory usage)
- Multiple runs to account for variance
- Specific hotspot identification, not just "it's slow"
Identify WHICH dimension: throughput, latency, memory, or CPU. Different problems need different solutions.
Step 4 Detail: Fundamental Fixes (APOSD Stage 2)
Before code-level changes, check for architectural fixes:
- Add a cache? Eliminate repeated expensive computation
- Better algorithm? e.g., balanced tree vs. list, hash map vs. linear search
- Bypass layers? e.g., kernel bypass for networking, direct buffer access
If a fundamental fix exists, implement it with standard design techniques. If not, continue down the tree.
Step 4 Extended: Critical Path Redesign (APOSD Stage 3)
When no fundamental fix is available, redesign the critical path:
- Ask: What is the smallest amount of code for the common case?
- Disregard existing code structure entirely
- Ignore special cases in current code -- consider only data needed for critical path
- Define "the ideal" -- simplest and fastest code assuming complete redesign freedom
- Design the rest of the class around these critical paths
Consolidation techniques:
| Technique | Example | |
|---|---|---|
| Encode multiple conditions in single value | Variable that is 0 when any special case applies | |
| Single test for multiple cases | Replace 6 individual checks with 1 combined check | |
| Combine layers into single method | Critical path handled in one method, not three | |
| Merge variables | Combine multiple values into single structure |
Code Tuning Procedure (ordered — each step's evidence feeds the next)
Only reached after completing the 7-step decision tree.
Technique Priority by Category
Logic:
- Stop testing when answer known (break, short-circuit)
- Order tests by frequency (most common first)
- Substitute table lookups for complex logic
- Use lazy evaluation
Loops:
- Unswitch (move invariant tests outside)
- Jam/fuse loops operating on same range
- Put busiest loop on inside
- Minimize work inside loops
- Use sentinel values for search loops
- Unroll ONLY if measured (can be -27% in Python!)
Data:
- Use integers instead of floating-point when possible
- Use fewest array dimensions
- Cache frequently computed values
- Precompute results where practical
Expressions:
- Initialize at compile time
- Exploit algebraic identities
- Use strength reduction (multiplication -> addition)
- Eliminate common subexpressions
After Making Changes
Checklist and code examples: Read(${CLAUDE_SKILL_DIR}/checklists.md)
Re-measure before keeping any change. Keep only if: significant speedup (with data), OR simpler AND at least as fast. Otherwise back it out. If a kept change degraded the structure, restore it as a separate refactor: Skill(code-foundations:cc-refactoring-guidance).
Red Flags
| Red Flag | Symptom | |
|---|---|---|
| Premature Optimization | Optimizing without measurement | |
| Death by Thousand Cuts | Many small inefficiencies, no single fix helps (5-10x slower) | |
| Pass-Through Methods | Identical signature to caller, unnecessary layer crossing | |
| Shallow Layers | Multiple layers providing same abstraction | |
| Repeated Special Cases | Same conditions checked multiple times | |
| Trading maintainability for <10% gain | Complex optimization for minor speedup |
Checker
Checklist: Read(${CLAUDE_SKILL_DIR}/checklists.md)
VIOLATION = clear anti-pattern; WARNING = needs measurement. CHECKER output: the ID'd checklist is the item set (the tables in this SKILL.md explain the items, they are not counted twice). Report each VIOLATION and WARNING as | Item | Status | Evidence | Location |; do not list passing or non-applicable items — close with one line N items checked, M pass, K n/a.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/performance-optimization/SKILL.md
Popularity
- Repository stars
- 268
- Repository forks
- 24
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ryanthedev/code-foundations/performance-optimization)