Performance optimization

From drvoss/everything-copilot-cli · View interactive version

Performance optimization is an AI agent skill from the GitHub repository drvoss/everything-copilot-cli. Use when performance is a real concern — measure first, isolate the bottleneck, and prove the improvement instead of guessing

How to use this skill

Skill file

Performance Optimization

Do not optimize by instinct. Start with measurement, change one thing at a time, and confirm the

result with the same metric you used at the beginning.

When to Use

When NOT to Use

| Instead of performance-optimization | Use |

|------------------------------------|-----|

| Obvious correctness bug | systematic-debugging |

| General frontend inspection without a clear perf question | browser-devtools |

| Micro-tuning without user impact | leave it alone |

| "Feels slow" with no measurement plan | define a measurable target first |

Workflow

1. Define the metric that matters

Pick the metric before touching code:

Write the target in one line:

Goal: reduce p95 /search latency from 850ms to under 400ms.

2. Capture a baseline

Measure the current state using the closest native tool:

# Node.js CPU profiling
node --prof server.js

# Frontend runtime inspection
# Use browser devtools / Lighthouse and record the before numbers

# Database query analysis
# EXPLAIN ANALYZE <query>

Keep the baseline numbers in the task notes, PR, or issue.

3. Find the dominant bottleneck

Look for the one thing consuming most of the time:

Use the 80/20 rule: fix the dominant bottleneck before touching minor inefficiencies.

4. Form one optimization hypothesis

Hypothesis: caching the normalized search filters will reduce repeated query-building work and cut p95 latency by ~30%.
Test: add the cache, rerun the same benchmark, compare p95 latency.
Rollback: remove the cache if latency does not improve or invalidation gets messy.

One hypothesis, one change, one measurement.

5. Re-measure with the same test

After each change:

  1. Re-run the same benchmark or profiling flow
  2. Compare against the original baseline
  3. Keep or revert based on evidence

If performance improves but correctness or maintainability regresses sharply, it is not a win.

6. Document the result

Record:

Practical Targets

| Area | Healthy target |

|------|----------------|

| LCP | <= 2.5s |

| INP | <= 200ms |

| CLS | <= 0.1 |

| API p95 latency | Fits product SLO; usually far below 1s for interactive endpoints |

| Slow DB query | Moves from table scan / many-row scan toward indexed, explainable execution |

Optimization Order

  1. Remove unnecessary work
  2. Fix algorithmic complexity
  3. Eliminate duplication or N+1 patterns
  4. Parallelize or pipeline safe independent work
  5. Cache with explicit invalidation rules
  6. Leave micro-optimizations for last

Common Mistakes

| Mistake | Fix |

|---------|-----|

| Optimizing before measuring | Record a baseline first |

| Changing five things at once | Make one testable change at a time |

| Chasing average latency only | Track tail latency (p95 / p99) too |

| Adding a cache without invalidation strategy | Define freshness, eviction, and rollback before shipping |

| Keeping a "faster" change that hurts readability for no user-visible gain | Revert it |

Verification

See Also

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.