skills/performance-optimization/SKILL.md
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.
npx skillsauth add ryanthedev/code-foundations performance-optimizationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Do not optimize based on intuition -- profile first.
No measurement = no optimization. This gate is non-negotiable.
This skill covers single-threaded, single-process code tuning for general-purpose computing.
Not covered (need specialized guidance):
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.
Each step is a gate. Do NOT skip steps.
1. Is the program correct and complete?
NO -> Make it correct first. STOP optimization.
YES -> Continue
2. Have you measured to find the actual bottleneck?
NO -> Profile/measure first. Do NOT guess.
YES -> Continue
3. Can requirements be relaxed?
YES -> Relax requirements. Done.
NO -> Continue
4. Can design/architecture solve it? (Stage 2: Fundamental Fixes)
YES -> Fix design. Done.
NO -> Continue
5. Can algorithm/data structure solve it?
YES -> Change algorithm. Done.
NO -> Continue
6. Can compiler flags help? (40-59% improvement possible)
YES -> Enable optimizations. Measure.
NO -> Continue
7. Is it in the <4% that causes >50% of runtime?
NO -> Do NOT optimize this code. Find actual hot spot.
YES -> PROCEED with code tuning (see below)
What counts as valid measurement:
Identify WHICH dimension: throughput, latency, memory, or CPU. Different problems need different solutions.
Before code-level changes, check for architectural fixes:
If a fundamental fix exists, implement it with standard design techniques. If not, continue down the tree.
When no fundamental fix is available, redesign the critical path:
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 |
Only reached after completing the 7-step decision tree.
1. Save working version (cannot revert without backup)
2. Make ONE change (multiple changes = unmeasurable)
3. Measure improvement (same workload, before/after)
4. Keep if faster, revert if not (no "close enough")
5. Repeat
Logic:
Loops:
Data:
Expressions:
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.
| 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 |
| Threshold/Rule | Value | Source | |----------------|-------|--------| | Hot spot concentration | <4% causes >50% runtime | Knuth 1971 | | Failed optimization rate | >50% negligible or negative | CC p.607 | | Compiler optimization gains | 40-59% improvement possible | CC p.596 | | I/O vs memory | ~1000x difference | CC p.591 |
Checklist: Read(${CLAUDE_SKILL_DIR}/checklists.md)
Output Format:
| Item | Status | Evidence | Location |
|------|--------|----------|----------|
| Measured before tuning? | VIOLATION | No profiler/measurement found | N/A |
| Loop unswitching opportunity | WARNING | Invariant if (debug) inside loop | app.py:142 |
Severity: VIOLATION (clear anti-pattern), WARNING (needs measurement), PASS (no issues)
| After | Next | |-------|------| | Optimization complete | Verify design not degraded | | Structure degraded | cc-refactoring-guidance |
devops
Implements the Standard/Full planning pipeline for Medium and Complex tasks: multi-step discovery, phase decomposition with skill matching, cross-cutting concerns, and plan emission with Gate fields.
development
Provides all 23 Gang of Four patterns as a decision guide: maps code symptoms to patterns, then loads the structural recipe for the selected pattern.
development
Applies Code Complete's scientific debugging method: STABILIZE → LOCATE → HYPOTHESIZE → EXPERIMENT → FIX → TEST → SEARCH. For active bug investigation, not QA process design or test coverage planning.
development
Generates or updates docs/code-standards.md by scanning the codebase for actual conventions. Produces an example-rich standards file optimized for LLM consumers, grounded in the project's real patterns.