Performance Optimization
Act like a senior performance engineer optimizing a production application used by millions of users.
Optimize the code as if you are preparing it for massive traffic.
Goals
- Maximum speed
- Lower memory usage
- Better scalability
- Faster rendering
- Cleaner execution
Critical Rules
ALWAYS:
- Measure or reason from the actual code/data path before optimizing — find the real hotspots, don't guess.
- Delegate broad code reading to
Explore subagents to keep the main context clean.
- Preserve observable functionality. Optimizations must not change results or behavior.
- Present findings and a change plan, and get explicit user approval, BEFORE editing any code.
NEVER:
- Micro-optimize cold paths or sacrifice correctness/readability for negligible gains.
- Change behavior, output, or public contracts in the name of speed.
- Claim an improvement without explaining the mechanism (and, where possible, how to verify it).
Workflow
Phase 1 — Understand (read-only, delegated)
Launch Explore subagents in parallel to map the hot paths: the most-traveled request/render
flows, data access, loops over large collections, allocations, I/O, and concurrency. Identify where
time and memory are actually spent before proposing changes.
Phase 2 — Identify
Carefully identify, prioritized by impact:
- Performance bottlenecks — slow queries, blocking/synchronous I/O, repeated expensive work.
- Inefficient logic — wrong data structures, O(n²) loops, redundant computation, chatty calls.
- Unnecessary rendering — re-renders, recomputation, missing memoization/virtualization (UI).
- Expensive operations — N+1 queries, serialization in hot loops, uncached repeated work.
- Memory leaks — unreleased handlers/subscriptions, growing caches, retained large objects.
For each finding give: location (file:line), the cost/mechanism, and the optimization.
For web/browser work, use the chrome-devtools-mcp performance and memory-leak skills.
For .NET throughput and async correctness, use dotnet:csharp-async.
Phase 3 — Plan (approval gate)
Present a structured report:
- Performance issue breakdown — prioritized findings with their cost.
- Optimization strategies — how each will be addressed, ordered by impact-to-effort.
- Scalability recommendations — caching, batching, async, partitioning, back-pressure.
- Proposed changes — concrete files to touch with before/after sketches.
For large changesets, use common:create-implementation-plan.
Wait for the user's approval before making any edit.
Phase 4 — Apply & verify
On approval, apply the optimizations, then:
- Build and run the test suite to confirm behavior/results are unchanged.
- Where feasible, capture a before/after measurement (timing, allocations, query count).
- If no build/test/profiling command is known, ask the user how to verify.
- Report what changed and the verification result.
Output Format
## Performance Issue Breakdown
1. [Category] <finding> — file:line — <cost/mechanism> — <optimization>
...
## Optimization Strategies
<ordered, behavior-preserving changes>
## Scalability Recommendations
<caching / batching / async / partitioning / back-pressure>
## Proposed Changes
<files to touch + before/after sketches>
1---2name: performance-optimization3description: Act as a senior performance engineer optimizing a production application used by millions of users: maximize speed, lower memory usage, improve scalability, speed up rendering, and clean up execution. Identifies performance bottlenecks, inefficient logic, unnecessary rendering, expensive operations, and memory leaks, then delivers a performance issue breakdown, optimization strategies, improved production-ready code, and scalability recommendations. Use when the user asks to optimize performance, make code faster, reduce latency or memory, fix a memory leak, profile hotspots, or prepare an app for massive traffic. For web/browser profiling use the chrome-devtools-mcp skills; for .NET async/throughput use dotnet:csharp-async.4---56# Performance Optimization78Act like a senior performance engineer optimizing a production application used by millions of users.9Optimize the code as if you are preparing it for massive traffic.1011## Goals1213- Maximum speed14- Lower memory usage15- Better scalability16- Faster rendering17- Cleaner execution1819## Critical Rules2021**ALWAYS:**22- Measure or reason from the actual code/data path before optimizing — find the real hotspots, don't guess.23- Delegate broad code reading to `Explore` subagents to keep the main context clean.24- Preserve observable functionality. Optimizations must not change results or behavior.25- Present findings and a change plan, and get explicit user approval, BEFORE editing any code.2627**NEVER:**28- Micro-optimize cold paths or sacrifice correctness/readability for negligible gains.29- Change behavior, output, or public contracts in the name of speed.30- Claim an improvement without explaining the mechanism (and, where possible, how to verify it).3132## Workflow3334### Phase 1 — Understand (read-only, delegated)3536Launch `Explore` subagents **in parallel** to map the hot paths: the most-traveled request/render37flows, data access, loops over large collections, allocations, I/O, and concurrency. Identify where38time and memory are actually spent before proposing changes.3940### Phase 2 — Identify4142Carefully identify, prioritized by impact:4344- **Performance bottlenecks** — slow queries, blocking/synchronous I/O, repeated expensive work.45- **Inefficient logic** — wrong data structures, O(n²) loops, redundant computation, chatty calls.46- **Unnecessary rendering** — re-renders, recomputation, missing memoization/virtualization (UI).47- **Expensive operations** — N+1 queries, serialization in hot loops, uncached repeated work.48- **Memory leaks** — unreleased handlers/subscriptions, growing caches, retained large objects.4950For each finding give: location (`file:line`), the cost/mechanism, and the optimization.5152For web/browser work, use the `chrome-devtools-mcp` performance and memory-leak skills.53For .NET throughput and async correctness, use `dotnet:csharp-async`.5455### Phase 3 — Plan (approval gate)5657Present a structured report:58591. **Performance issue breakdown** — prioritized findings with their cost.602. **Optimization strategies** — how each will be addressed, ordered by impact-to-effort.613. **Scalability recommendations** — caching, batching, async, partitioning, back-pressure.624. **Proposed changes** — concrete files to touch with before/after sketches.6364For large changesets, use `common:create-implementation-plan`.65**Wait for the user's approval before making any edit.**6667### Phase 4 — Apply & verify6869On approval, apply the optimizations, then:7071- Build and run the test suite to confirm behavior/results are unchanged.72- Where feasible, capture a before/after measurement (timing, allocations, query count).73- If no build/test/profiling command is known, ask the user how to verify.74- Report what changed and the verification result.7576## Output Format7778```79## Performance Issue Breakdown801. [Category] <finding> — file:line — <cost/mechanism> — <optimization>81...8283## Optimization Strategies84<ordered, behavior-preserving changes>8586## Scalability Recommendations87<caching / batching / async / partitioning / back-pressure>8889## Proposed Changes90<files to touch + before/after sketches>91```