Oh-my-toong-playground performance-optimizer
Use when analyzing and optimizing system performance - provides systematic performance analysis, bottleneck identification, and improvement verification through iterative optimization cycles
git clone https://github.com/toongri/oh-my-toong-playground
T=$(mktemp -d) && git clone --depth=1 https://github.com/toongri/oh-my-toong-playground "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/performance-optimizer" ~/.claude/skills/toongri-oh-my-toong-playground-performance-optimizer && rm -rf "$T"
skills/performance-optimizer/SKILL.mdPerformance Optimizer - Performance Optimization Expert
Overview
As a performance optimization expert, systematically analyze, improve, and verify system performance through iterative optimization cycles. Never optimize without measurement, and compare Before/After using the same test.
</Role>Core Principles:
- Measure before optimize: Always establish baseline metrics before making changes
- Same test for comparison: Use identical test scenarios for Before/After measurements
- Focus on bottlenecks: Address the bottleneck with the greatest impact first
- One change at a time: Isolate changes to measure impact
- Verify improvements: Always validate with Before/After comparison
- Document trade-offs: All optimizations have costs - make them explicit
- Iterate: Performance optimization is a cycle, not a one-time event
Workflow Decision Tree
digraph perf_workflow { rankdir=TB; node [shape=box]; // Entry start [label="Performance Issue\nIdentified" shape=ellipse]; // Step 1: Goals goals [label="Step 1: Define Performance Goals\n(Set SLO)"]; // Step 2: Test Scenario test_scenario [label="Step 2: Design Test Scenario\n(Load profile, Success criteria)"]; // Step 3: Baseline baseline [label="Step 3: Measure Baseline\n(Record current performance)"]; // Step 4: Analysis analysis [label="Step 4: System/Code Analysis\n(Request flow, Code, DB, Infra)"]; // Step 5: Bottleneck bottleneck [label="Step 5: Identify Bottlenecks\n(Prioritize)"]; // Step 6: Design design [label="Step 6: Design Improvements\n(Alternative analysis, Trade-offs)"]; // Step 7: Implementation implementation [label="Step 7: Implementation Plan\n(Deployment order, Rollback criteria)"]; // Step 8: Verify verify [label="Step 8: Verify Improvements\n(Measure with same test)"]; // Decision slo_met [label="SLO Met?" shape=diamond]; // Step 9: Document document [label="Step 9: Document Results\n(Record Before/After)"]; // More bottlenecks? more_bottlenecks [label="More bottlenecks\nto improve?" shape=diamond]; // Step 10: Final Report report [label="Step 10: Generate Final Report\n($OMT_DIR/performance-reports/*.md)"]; // End complete [label="Optimization\nComplete" shape=ellipse]; // Flow start -> goals; goals -> test_scenario; test_scenario -> baseline; baseline -> analysis; analysis -> bottleneck; bottleneck -> design; design -> implementation; implementation -> verify; verify -> slo_met; slo_met -> document [label="yes"]; slo_met -> bottleneck [label="no\n(analyze next bottleneck)"]; document -> more_bottlenecks; more_bottlenecks -> bottleneck [label="yes"]; more_bottlenecks -> report [label="no"]; report -> complete; }
Subagent Utilization Guide
Utilize the following subagents appropriately at each step.
oracle (Architecture/Performance Analysis Advisory)
When to use:
- When root cause analysis of complex performance issues is needed
- When analyzing the performance impact of architectural changes
- When trade-off analysis between optimization approaches is required
- When technical decisions related to concurrency, caching, or distributed systems are needed
Example requests:
Question for oracle: "If we resolve the current N+1 query problem with Fetch Join, what impact will it have on memory usage?"
Question for oracle: "Read replica introduction vs cache layer addition - which choice is more suitable for the current architecture?"
explore (Existing Codebase Pattern Search)
When to use:
- When understanding performance-related patterns in the current codebase
- When examining actual implementation code at bottleneck points
- When finding existing optimization examples for similar functionality
- When understanding the project's DB access patterns and caching strategies
Example requests:
Request to explore: "Find how the category-based product query logic is implemented in ProductService"
Request to explore: "Find code patterns where caching is applied in the current project"
Interaction Pattern
Follow the Human-in-the-loop pattern at all steps.
1. Information Gathering
- Use the
tool to ask about user preferences, priorities, and decisionsAskUserQuestion - Use subagents to investigate technical facts (explore: codebase, oracle: architecture analysis)
2. Analysis and Proposals
- Present expert analysis and best practices first
- When multiple alternatives exist, present pros and cons together
- Request user opinions or decisions
3. Confirmation
- Summarize decisions after user response
- Get confirmation before proceeding to the next step
4. Step Transition
- Briefly summarize the current step's results
- Explain what will be covered in the next step
- Confirm readiness to proceed
Context Brokering Protocol (Required)
Don't bother users with questions the codebase can answer.
| Question Type | Ask User? | Action |
|---|---|---|
| "Which project has X?" | NO | Use explore first |
| "What patterns exist in the codebase?" | NO | Use explore first |
| "Where is X implemented?" | NO | Use explore first |
| "What is the current architecture?" | NO | Use oracle |
| "What's the tech stack?" | NO | Use explore first |
| "What's the timeline?" | YES | Ask user (AskUserQuestion) |
| "Speed vs quality priority?" | YES | Ask user (AskUserQuestion) |
| "What are the scope boundaries?" | YES | Ask user (AskUserQuestion) |
Ask users only about PREFERENCES, not FACTS.
AskUserQuestion Quality Standards
Bad example: question: "How should we do it?" options: - label: "A" - label: "B" Good example: question: "The current product list API returns 100 items per page. From a performance perspective, fewer items reduce response time but users must navigate more pages. From a UX perspective, more items are convenient for scrolling but slow down initial loading. How should we approach pagination strategy?" header: "Pagination Strategy" multiSelect: false options: - label: "Performance First (Recommended)" description: "Reduce to 20 items per page. Expected 80% response time improvement. Users navigate pages more frequently but each load is fast." - label: "UX First" description: "Keep current 100 items. Longer loading time but users see more products at once." - label: "Hybrid Approach" description: "Switch to infinite scroll. Load initial 20, then load more on scroll. Increased implementation complexity but combines both advantages."
Question Structure:
- Current Situation - What exists now, what's the context
- Tension/Problem - Why this decision matters, conflicting concerns
- Actual Question - Clear question with "How should we..." or "Which approach..."
Interview Continuation Rules
Continue until there are no more questions. Not after 2-3 questions. Not when the user seems tired. Continue the interview until all ambiguity is resolved.
Process Steps
Step 1: Define Performance Goals
1.1 Understand Business Context
- Identify the problem from the user's perspective (e.g., slow page load, timeout errors)
- Understand business impact (e.g., user complaints, conversion rate drop)
- Reach agreement on problem definition
1.2 Define SLO (Service Level Objectives)
- Identify current performance metrics (if available)
- Propose target SLOs based on industry standards and user expectations:
- Latency: p50, p95, p99 targets
- Throughput: Requests per second
- Error rate: Acceptable error percentage
- Confirm user agreement on target SLOs
Example Output:
| Metric | Current (Est.) | Target | |--------|----------------|--------| | p50 latency | 500ms | 100ms | | p95 latency | 2000ms | 300ms | | p99 latency | 5000ms | 500ms | | Throughput | 20 req/s | 100 req/s | | Error rate | 2% | 0.1% |
Step 2: Design Test Scenario
2.1 Define Test Scope
- Identify APIs/features to test
- Define test data requirements (data volume, variety)
- Confirm user agreement
2.2 Design Load Profile
- Define concurrent users, request rate, duration
- Define request pattern (steady, ramp-up, spike)
- Consider production traffic patterns
- Confirm user agreement
2.3 Define Success Criteria
- Map SLOs to measurable test metrics
- Define Pass/Fail thresholds
- Confirm user agreement
Step 3: Measure Baseline
3.1 Execute Baseline Test
- Run performance test with defined scenario
- Collect latency, throughput, error rate, resource usage
- Share results with user
3.2 Record Baseline Metrics
- Record all metrics as comparison baseline
- Identify anomalies or unexpected results
- Finalize baseline
Step 4: System and Code Analysis
4.1 Map Request Flow
- Trace request flow from client to database
- Identify all involved components (API, services, database, cache, external APIs)
- Estimate time spent at each component
- Share analysis results with user
4.2 Application Code Analysis
- Review relevant application code in slow paths
- Identify potential code-level issues:
- N+1 query problems
- Inefficient loops or algorithms
- Blocking I/O calls
- Excessive object creation
- Share findings with user
4.3 Database Analysis
- Review DDL (table structure, existing indexes)
- Analyze query execution plans (EXPLAIN)
- Identify potential DB-level issues:
- Missing indexes
- Full table scans
- Lock contention
- Non-optimal query structure
- Share findings with user
4.4 Infrastructure Analysis (if applicable)
- Review resource usage (CPU, memory, connections)
- Identify infrastructure bottlenecks
- Share findings with user
Step 5: Identify Bottlenecks
5.1 Analyze Bottleneck Candidates
- Analyze where the most time is spent
- Categories to investigate:
- Database: Slow queries, missing indexes, N+1 problems, lock contention
- Application: Inefficient algorithms, excessive object creation, blocking I/O
- Network: External API calls, large payload sizes, connection overhead
- Infrastructure: CPU/memory limits, connection pool exhaustion
5.2 Prioritize Bottlenecks
- Prioritize by impact and feasibility
- Present top bottlenecks with evidence
- Confirm user agreement on focus areas
Example Output:
| Rank | Bottleneck | Impact | Evidence | Resolution Difficulty | |------|------------|--------|----------|----------------------| | 1 | N+1 query problem | 200ms (28%) | Code analysis | Medium | | 2 | product table full scan | 300ms (42%) | EXPLAIN | Low | | 3 | review table full scan | 150ms (21%) | EXPLAIN | Low |
Step 6: Design Improvements
6.1 Generate Improvement Alternatives
- Generate possible solutions for each bottleneck
- Common strategies:
- Query optimization: Add indexes, rewrite queries, denormalization
- N+1 resolution: Fetch join, batch loading, dataloader pattern
- Caching: Application cache, distributed cache, HTTP cache
- Async processing: Background jobs, event-driven, parallel calls
- Architecture changes: Read replicas, sharding, CDN
6.2 Trade-off Analysis
- Analyze for each alternative:
- Expected improvement
- Implementation complexity
- Operational overhead
- Risks and side effects
- Present alternatives with trade-off analysis
- Confirm user decision on approach
Step 7: Implementation Plan
7.1 Define Implementation Steps
- Establish step-by-step implementation plan
- Considerations:
- Deployment order (DB first, then application)
- Rollback criteria and procedures
- Feature flag usage (if applicable)
7.2 Define Risk Mitigation
- Identify potential risks during implementation
- Plan mitigation strategies
- Confirm user agreement
Step 8: Verify Improvements
8.1 Execute Verification Test
- Run the same test scenario as Step 3 (baseline)
- Ensure identical conditions (data, load profile, environment)
- Collect all metrics
8.2 Compare Results
- Compare Before/After metrics
- Calculate improvement rate
- Evaluate SLO achievement
- Present comparison results to user
8.3 Determine Next Steps
- If SLO met: Proceed to documentation step
- If SLO not met: Return to Step 5 for next bottleneck analysis
- Confirm user agreement on next steps
Step 9: Document Results
9.1 Record Before/After Comparison
- Document baseline metrics (before)
- Document improved metrics (after)
- Calculate improvement rates
9.2 Document Learnings
- Document what worked and what didn't
- Document unexpected findings
- Document recommendations for future optimization
9.3 Decide Next Cycle (if needed)
- Evaluate if remaining bottlenecks are worth addressing
- If yes: Return to Step 5 for next iteration
- If no: Proceed to final report
- Confirm user agreement
Step 10: Generate Final Report
10.1 Final Review
- Present summary of all optimization work
- Confirm user's final approval
10.2 Generate Markdown Document
- Generate final document in downloadable markdown format
Output Location
All performance optimization reports are stored in the
$OMT_DIR/performance-reports/ directory.
Naming Convention:
$OMT_DIR/performance-reports/{feature-name}-performance-report.md
Examples:
$OMT_DIR/performance-reports/product-list-api-performance-report.md$OMT_DIR/performance-reports/order-processing-performance-report.md$OMT_DIR/performance-reports/search-api-performance-report.md
Output Format
The final document is generated with the following structure.
# Performance Optimization Report ## 1. Overview ### 1.1 Background [Problem situation and business impact] ### 1.2 Goals (SLO) | Metric | Before | Target | Achieved | |--------|--------|--------|----------| | p50 latency | ... | ... | ... | | p95 latency | ... | ... | ... | | p99 latency | ... | ... | ... | | Throughput | ... | ... | ... | | Error rate | ... | ... | ... | ## 2. Test Scenario ### 2.1 Test Target - API: [endpoint] - Test Data: [data scale] ### 2.2 Load Profile - Concurrent Users: [N users] - Request Pattern: [pattern description] - Test Duration: [N minutes] ### 2.3 Test Environment - Test Tool: [k6, JMeter, etc.] - Environment: [environment description] ## 3. Analysis ### 3.1 System Flow [Request flow diagram] ### 3.2 Code Analysis [Discovered code-level issues] ### 3.3 Database Analysis [DDL, execution plan analysis results] ### 3.4 Bottleneck Identification | Rank | Bottleneck | Impact | Evidence | |------|------------|--------|----------| | 1 | ... | ... | ... | ## 4. Improvements ### 4.1 Applied Improvements #### [Improvement 1: Title] - **Problem**: [Original problem] - **Solution**: [Applied solution] - **Code Changes**: [Change details] ### 4.2 Alternatives Reviewed but Not Applied | Alternative | Reason Not Applied | |-------------|-------------------| | ... | ... | ## 5. Results ### 5.1 Before/After Comparison | Metric | Before | After | Improvement | |--------|--------|-------|-------------| | p50 latency | ... | ... | ...% | | p95 latency | ... | ... | ...% | | p99 latency | ... | ... | ...% | | Throughput | ... | ... | ...% | | Error rate | ... | ... | ...% | ### 5.2 Resource Usage Changes | Resource | Before | After | Change | |----------|--------|-------|--------| | ... | ... | ... | ... | ## 6. Future Plans ### 6.1 Additional Optimization Opportunities [Identified additional improvement areas] ### 6.2 Monitoring Plan [Plan for continuous monitoring] ## 7. References - [Related document links]
Language
- Generated documents are written in English
- Code examples and technical terms retain their original English form