[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CHWFEQTFC1EFZ0WSTBVZ4F":3,"skill-same:01M6CHWFEQTFC1EFZ0WSTBVZ4F":81},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":25,"publishedAt":43,"linkOnly":44,"markdownContent":45,"markdownBody":46,"frontMatter":47,"refName":59,"commitSha":60,"skillDirectory":61,"forksCount":62,"repositoryHtmlUrl":63,"repositoryHomepageUrl":64,"ownerHtmlUrl":65,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":66,"install":67,"resources":80},"01M6CHWFEQTFC1EFZ0WSTBVZ4F","optimize",null,"[ADD v0.11.0] Performance optimization pass — identify and fix bottlenecks","MountainUnicorn\u002Fadd","MountainUnicorn","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F199411549?v=4","01M6CHRAWFWD275ANP1S2A0HXC","01M6CHRB0QE1678D913B438SAR",11,"MIT","https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Fplugins\u002Fadd\u002Fskills\u002Foptimize\u002FSKILL.md",[17,22],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000009","前端开发","SCENARIO","使用场景",{"categoryNo":23,"categoryName":24,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000023","Skill与智能体开发",[5,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42],"read","task","backend","v0","fix","profile","edit","write","frontend","grep","Rules","performance optimization","Bash","first","Optimization","telemetry","performance","2026-11-10 10:12:30",false,"---\ndescription: \"[ADD v0.11.0] Performance optimization pass — identify and fix bottlenecks\"\nargument-hint: \"[--scope backend|frontend|full] [--profile-first]\"\nallowed-tools: [Read, Write, Edit, Glob, Grep, Bash, Task]\nreferences: [\"skill-epilogue.md\", \"rules\u002Ftelemetry.md\"]\n---\n\n# ADD Optimize Skill v0.11.0\n\nIdentify and fix performance bottlenecks. This skill profiles code to find slow operations, suggests optimizations, and implements them with test-driven discipline.\n\n## Overview\n\nThe Optimize skill improves application performance while maintaining correctness. It:\n- Profiles code to identify bottlenecks\n- Quantifies performance issues\n- Suggests targeted optimizations\n- Implements with TDD (tests before optimization)\n- Verifies improvements with measurements\n- Documents optimizations for future maintainers\n\nPerformance optimization follows TDD discipline: write tests that capture performance expectations before implementing optimizations.\n\n## Pre-Flight Checks\n\n1. **Verify implementation exists**\n   - Identify implementation files (src\u002F, app\u002F, etc.)\n   - Verify code is in GREEN state (all tests passing)\n   - Halt if tests not passing (optimize only stable code)\n\n2. **Load configuration**\n   - Read .add\u002Fconfig.json\n   - Extract performance targets:\n     - perf.pageLoadTime (e.g., \u003C 2 seconds)\n     - perf.responseTime (e.g., \u003C 100ms)\n     - perf.memoryLimit (e.g., \u003C 50MB)\n     - perf.bundleSize (e.g., \u003C 500KB)\n\n3. **Determine scope**\n   - Use --scope flag to target: backend, frontend, or full\n   - Default: full system\n   - Scope guides which profiling tools to use\n\n4. **Check for profiling data**\n   - If --profile-first: profile before optimization\n   - Otherwise, use existing profile if available\n   - Or ask user for baseline metrics\n\n5. **Identify profiling tools**\n   - Backend: py-spy, perf, go pprof, node --prof, etc.\n   - Frontend: Chrome DevTools, Lighthouse, WebPageTest\n   - Database: EXPLAIN ANALYZE, pg_stat_statements, etc.\n\n6. **Check for session handoff** — per the Session-Handoff Preflight in `${CLAUDE_PLUGIN_ROOT}\u002Freferences\u002Fskill-epilogue.md`\n\n## Execution Steps\n\n### Step 1: Baseline Profiling (if --profile-first)\n\nEstablish baseline measurements:\n\n**For Backend (Python)**:\n```bash\n# Profile with py-spy\npy-spy record -o profile.svg -- python -m pytest tests\u002F\n\n# Or use cProfile\npython -m cProfile -s cumulative app.py > profile.txt\n\n# Database queries\nEXPLAIN ANALYZE SELECT ...\n```\n\nCapture metrics:\n- Request\u002Fresponse time per endpoint\n- Memory usage peak\n- CPU utilization\n- Database query times\n- Cache hit rates\n\n**For Frontend (JavaScript)**:\n```bash\n# Lighthouse CLI\nnpm install -g lighthouse\nlighthouse https:\u002F\u002Flocalhost:3000 --output json --output html\n\n# Or use Chrome DevTools\n# DevTools → Performance tab → Record\n```\n\nCapture metrics:\n- Page load time (FCP, LCP, FID)\n- Time to Interactive (TTI)\n- Cumulative Layout Shift (CLS)\n- JavaScript execution time\n- Network waterfall\n\n**For Full System**:\n- Run both backend and frontend profiling\n- Capture end-to-end latencies\n\n**Create Baseline Report**:\n```\n# Performance Baseline\n\n## Backend Metrics\n- Average response time: 250ms (target: 100ms) ⚠\n- 95th percentile response: 800ms (target: 200ms) ⚠\n- Peak memory: 120MB (target: 50MB) ⚠\n- Database query time: 180ms average (target: 50ms) ⚠\n- Cache hit rate: 62% (target: 85%) ⚠\n\n## Frontend Metrics\n- First Contentful Paint: 2.1s (target: 1.5s) ⚠\n- Largest Contentful Paint: 3.2s (target: 2.5s) ⚠\n- JavaScript execution: 450ms (target: 200ms) ⚠\n- Bundle size: 580KB (target: 300KB) ⚠\n\n## Identified Bottlenecks (Priority Order)\n1. Database query in \u002Fapi\u002Flist endpoint (180ms)\n2. JavaScript bundle parsing (150ms)\n3. Form validation on every keystroke (50ms)\n4. Unoptimized images (120KB uncompressed)\n5. Missing indexes on user lookup\n```\n\n### Step 2: Analyze & Prioritize Bottlenecks\n\nFor each bottleneck:\n\n1. **Quantify the impact**\n   - How much time does it consume?\n   - How often does it run?\n   - How many users affected?\n   - What's the cost of not fixing it?\n\n2. **Estimate improvement potential**\n   - What's a realistic target?\n   - How much better could it be?\n   - What's the effort to optimize?\n\n3. **Calculate ROI**\n   - Effort \u002F Time saved = Return on Investment\n   - Prioritize high-ROI items\n\n4. **Group by category**\n   - Database: queries, indexes, N+1 problems\n   - Algorithm: loops, recursion, sorting\n   - Memory: caching, allocation, GC\n   - Network: bundling, compression, parallelization\n   - Frontend: rendering, JavaScript, images\n\nExample prioritization:\n```\nBottleneck | Time | Impact | Effort | ROI | Priority |\n-----------|------|--------|--------|-----|----------|\nDB indexes | 180ms | High | 2h | 90x | 1 |\nBundle split | 150ms | High | 4h | 37x | 2 |\nValidation debounce | 50ms | Low | 1h | 50x | 3 |\nImage optimization | 120ms | Medium | 3h | 40x | 4 |\nCaching | 100ms | Medium | 3h | 33x | 5 |\n```\n\n### Step 3: Plan Optimizations\n\nFor each optimization:\n\n1. **Specify the optimization**\n   - What will change?\n   - Why will it help?\n   - What's the expected improvement?\n\n2. **Plan with TDD**\n   - What tests capture the optimization?\n   - Performance assertion: `assertLatency(operation, maxMs)`\n   - Can you write test before optimization?\n\n3. **Consider trade-offs**\n   - Memory vs. CPU tradeoff\n   - Complexity vs. performance\n   - Maintainability impact\n\n4. **Document approach**\n   - How will it be measured?\n   - How will success be verified?\n   - What's the fallback if it breaks?\n\nExample optimization plan:\n```\n# Optimization 1: Add database index on user_id\n\nBottleneck: User lookup query takes 180ms\nCurrent: SELECT * FROM orders WHERE user_id = ?\n         (full table scan on 1M rows)\n\nOptimization: CREATE INDEX idx_orders_user_id ON orders(user_id)\n\nExpected improvement: 180ms → 5ms (35x faster)\nTrade-offs: Slight write performance impact, +10MB storage\n\nTest plan:\n- test_list_orders_within_performance_budget() (max 50ms)\n- Verify with: pytest test_perf.py::test_list_orders_latency\n\nFallback: Drop index if causes write performance issues\n```\n\n### Step 4: Implement Optimizations with TDD\n\nFor each optimization, follow TDD discipline:\n\n**Step 4a: Write Performance Test**\n\n```python\nimport pytest\nimport time\n\ndef test_list_orders_performance():\n    \"\"\"Orders list should return \u003C 50ms for 1000 orders\"\"\"\n    # Arrange: Create test data\n    user = create_test_user()\n    for i in range(1000):\n        create_test_order(user)\n\n    # Act: Time the operation\n    start = time.perf_counter()\n    orders = get_user_orders(user)\n    duration = time.perf_counter() - start\n\n    # Assert: Verify performance\n    assert duration \u003C 0.050, f\"Got {duration*1000:.1f}ms, target \u003C 50ms\"\n    assert len(orders) == 1000\n```\n\n**Step 4b: Run Test - Verify It Fails**\n\n```bash\npytest test_perf.py::test_list_orders_performance -v\n# FAILED - got 180ms, target 50ms\n```\n\n**Step 4c: Implement Optimization**\n\nFor database index optimization:\n```sql\n-- migrations\u002F001_add_user_index.sql\nCREATE INDEX idx_orders_user_id ON orders(user_id);\n```\n\nFor algorithm optimization:\n```python\n# Before: O(n²) algorithm\ndef find_duplicates(items):\n    duplicates = []\n    for i, item in enumerate(items):\n        for j in range(i+1, len(items)):\n            if items[i] == items[j]:\n                duplicates.append(item)\n    return duplicates\n\n# After: O(n) algorithm\ndef find_duplicates(items):\n    seen = set()\n    duplicates = set()\n    for item in items:\n        if item in seen:\n            duplicates.add(item)\n        seen.add(item)\n    return list(duplicates)\n```\n\nFor bundle optimization:\n```javascript\n\u002F\u002F Before: Single large bundle (580KB)\nimport * as app from '.\u002Fapp.js'; \u002F\u002F all code\n\n\u002F\u002F After: Code splitting\n\u002F\u002F main.js (180KB)\nimport { HomePage } from '.\u002Fpages\u002Fhome.js';\n\u002F\u002F admin.js (150KB) - loaded on demand\n\u002F\u002F reports.js (120KB) - loaded on demand\n```\n\n**Step 4d: Run Test - Verify It Passes**\n\n```bash\npytest test_perf.py::test_list_orders_performance -v\n# PASSED - got 8ms, target 50ms ✓\n```\n\n**Step 4e: Verify No Regression**\n\nRun full test suite to ensure optimization doesn't break anything:\n```bash\nnpm test  # or pytest\n# All tests pass ✓\n```\n\n### Step 5: Measure & Document Results\n\nAfter implementing optimization:\n\n1. **Measure actual improvement**\n   ```\n   Before: 180ms average\n   After: 8ms average\n   Improvement: 95.6% faster (22.5x improvement)\n   Target met: ✓ (8ms \u003C 50ms target)\n   ```\n\n2. **Update performance baseline**\n   - Record new metrics\n   - Compare to targets\n   - Identify next bottleneck\n\n3. **Document in code**\n   ```python\n   def get_user_orders(user_id):\n       \"\"\"Retrieve user's orders.\n\n       Performance: \u003C 10ms (uses index on user_id)\n\n       Note: This uses an indexed query to keep latency low.\n       If you need to add more WHERE clauses, ensure they\n       are also indexed or consider query optimization.\n\n       See: docs\u002Fperformance.md for optimization history\n       \"\"\"\n       return db.query(\n           \"SELECT * FROM orders WHERE user_id = ? ORDER BY created DESC\",\n           [user_id]\n       )\n   ```\n\n4. **Create performance documentation**\n   - Create docs\u002Fperformance.md if not exists\n   - Record optimization history\n   - Document performance targets\n   - Link to profiling data\n\n   ```markdown\n   # Performance Documentation\n\n   ## Performance Targets\n   - Page load time: \u003C 2s\n   - API response: \u003C 100ms (p95)\n   - Bundle size: \u003C 300KB\n\n   ## Optimization History\n\n   ### 2025-02-07: Database Index on user_id\n   - Problem: User orders query took 180ms\n   - Solution: Added index on orders.user_id\n   - Result: Now 8ms (22.5x improvement)\n   - Test: test_list_orders_performance\n   - Status: ✓ Deployed to production\n\n   ### 2025-02-06: Code splitting\n   - Problem: Bundle size 580KB, slow initial load\n   - Solution: Split into main (180KB) + lazy chunks\n   - Result: FCP reduced from 2.1s to 1.2s\n   - Test: test_first_contentful_paint\n   - Status: ✓ Deployed to production\n\n   ## Current Performance Profile\n   - Average API response: 45ms (target: 100ms) ✓\n   - Page load FCP: 1.2s (target: 1.5s) ✓\n   - Bundle size: 280KB (target: 300KB) ✓\n   - Memory peak: 45MB (target: 50MB) ✓\n   ```\n\n## Output Format\n\nUpon completion, output:\n\n```\n# Performance Optimization Complete ✓\n\n## Optimizations Applied\n- Count: {N} optimizations implemented\n- All tests passing: ✓\n\n## Results Summary\n| Optimization | Before | After | Improvement |\n|--------------|--------|-------|-------------|\n| Database query | 180ms | 8ms | 95.6% ↓ |\n| Bundle size | 580KB | 280KB | 51.7% ↓ |\n| Form validation latency | 50ms | 15ms | 70% ↓ |\n\n## Performance Targets Status\n- Page load (FCP): 1.2s (target: 1.5s) ✓\n- API response (p95): 45ms (target: 100ms) ✓\n- Bundle size: 280KB (target: 300KB) ✓\n- Memory peak: 45MB (target: 50MB) ✓\n\n## Scope Optimized\n- Backend: ✓\n- Frontend: ✓\n- Database: ✓\n\n## Tests Updated\n- Performance tests: {count} new tests\n- All tests passing: {count}\u002F{count}\n\n## Documentation\n- Performance profile: docs\u002Fperformance.md\n- Optimization log: [detailed results]\n\n## Next Steps\n1. Review profile and optimization decisions\n2. Run full quality gates: \u002Fadd:verify --level deploy\n3. Deploy to staging and monitor\n4. If all good, deploy to production\n\n## Performance Test Results\n- test_list_orders_performance: PASS (8ms)\n- test_form_validation_latency: PASS (15ms)\n- test_bundle_load_time: PASS (0.8s)\n- test_memory_usage: PASS (45MB)\n```\n\n## Progress Tracking\n\n**Tasks to create** (mechanics per `${CLAUDE_PLUGIN_ROOT}\u002Freferences\u002Fskill-epilogue.md`):\n\n| Phase | Subject | activeForm |\n|-------|---------|------------|\n| Profile | Profiling performance baseline | Profiling performance... |\n| Bottlenecks | Identifying bottlenecks | Identifying bottlenecks... |\n| Optimize | Applying optimizations | Applying optimizations... |\n| Verify | Verifying performance improvements | Verifying improvements... |\n\n## Error Handling\n\n**Performance test not passing after optimization**\n- Review the implementation change\n- Check for unintended side effects\n- Verify profiling methodology\n- Try different optimization approach\n- Revert and try next highest-ROI bottleneck\n\n**Optimization breaks other tests**\n- Performance gained comes at correctness cost (bad)\n- Revert the optimization\n- Find alternative approach\n- Document why that approach won't work\n\n**Unable to reach target**\n- Document realistic achievable target\n- Revisit optimization with different approach\n- Consider if target is unrealistic\n- Flag for architecture review\n\n**Profiling tools not available**\n- Install tools: pip install py-spy, npm install -g lighthouse\n- Or use alternative profilers available\n- Document which tools were used\n\n## Integration with Other Skills\n\n- Used after \u002Fadd:tdd-cycle completes (code is stable)\n- Used before \u002Fadd:deploy to ensure performance requirements met\n- \u002Fadd:verify validates that optimization doesn't break tests\n- Performance tests become part of permanent test suite\n\n## Configuration in .add\u002Fconfig.json\n\n```json\n{\n  \"perf\": {\n    \"pageLoadTime\": 2.0,\n    \"responseTime\": 100,\n    \"memoryLimit\": 50,\n    \"bundleSize\": 300,\n    \"profiler\": \"chrome-devtools\",\n    \"targetPlatforms\": [\"web\", \"mobile\"]\n  }\n}\n```\n\n## Performance Testing Best Practices\n\n1. **Test real scenarios**\n   - Use realistic data volumes\n   - Test with production-like load\n   - Consider network latency (for e2e)\n\n2. **Measure consistently**\n   - Run tests multiple times (warm up JIT)\n   - Use standard hardware for benchmarks\n   - Control for other system activity\n\n3. **Set realistic targets**\n   - Based on business needs\n   - Based on competitive analysis\n   - Based on user experience standards\n\n4. **Monitor regressions**\n   - Keep performance tests in CI\n   - Alert on performance degradation\n   - Compare against baseline\n\n5. **Document trade-offs**\n   - Every optimization has trade-offs\n   - Complexity vs. performance\n   - Memory vs. CPU\n   - Development time vs. speed\n\nEnd-of-skill epilogue: follow `${CLAUDE_PLUGIN_ROOT}\u002Freferences\u002Fskill-epilogue.md` (observation + learning checkpoint + progress tracking).\n","# ADD Optimize Skill v0.11.0\n\nIdentify and fix performance bottlenecks. This skill profiles code to find slow operations, suggests optimizations, and implements them with test-driven discipline.\n\n## Overview\n\nThe Optimize skill improves application performance while maintaining correctness. It:\n- Profiles code to identify bottlenecks\n- Quantifies performance issues\n- Suggests targeted optimizations\n- Implements with TDD (tests before optimization)\n- Verifies improvements with measurements\n- Documents optimizations for future maintainers\n\nPerformance optimization follows TDD discipline: write tests that capture performance expectations before implementing optimizations.\n\n## Pre-Flight Checks\n\n1. **Verify implementation exists**\n   - Identify implementation files (src\u002F, app\u002F, etc.)\n   - Verify code is in GREEN state (all tests passing)\n   - Halt if tests not passing (optimize only stable code)\n\n2. **Load configuration**\n   - Read .add\u002Fconfig.json\n   - Extract performance targets:\n     - perf.pageLoadTime (e.g., \u003C 2 seconds)\n     - perf.responseTime (e.g., \u003C 100ms)\n     - perf.memoryLimit (e.g., \u003C 50MB)\n     - perf.bundleSize (e.g., \u003C 500KB)\n\n3. **Determine scope**\n   - Use --scope flag to target: backend, frontend, or full\n   - Default: full system\n   - Scope guides which profiling tools to use\n\n4. **Check for profiling data**\n   - If --profile-first: profile before optimization\n   - Otherwise, use existing profile if available\n   - Or ask user for baseline metrics\n\n5. **Identify profiling tools**\n   - Backend: py-spy, perf, go pprof, node --prof, etc.\n   - Frontend: Chrome DevTools, Lighthouse, WebPageTest\n   - Database: EXPLAIN ANALYZE, pg_stat_statements, etc.\n\n6. **Check for session handoff** — per the Session-Handoff Preflight in `${CLAUDE_PLUGIN_ROOT}\u002Freferences\u002Fskill-epilogue.md`\n\n## Execution Steps\n\n### Step 1: Baseline Profiling (if --profile-first)\n\nEstablish baseline measurements:\n\n**For Backend (Python)**:\n```bash\n# Profile with py-spy\npy-spy record -o profile.svg -- python -m pytest tests\u002F\n\n# Or use cProfile\npython -m cProfile -s cumulative app.py > profile.txt\n\n# Database queries\nEXPLAIN ANALYZE SELECT ...\n```\n\nCapture metrics:\n- Request\u002Fresponse time per endpoint\n- Memory usage peak\n- CPU utilization\n- Database query times\n- Cache hit rates\n\n**For Frontend (JavaScript)**:\n```bash\n# Lighthouse CLI\nnpm install -g lighthouse\nlighthouse https:\u002F\u002Flocalhost:3000 --output json --output html\n\n# Or use Chrome DevTools\n# DevTools → Performance tab → Record\n```\n\nCapture metrics:\n- Page load time (FCP, LCP, FID)\n- Time to Interactive (TTI)\n- Cumulative Layout Shift (CLS)\n- JavaScript execution time\n- Network waterfall\n\n**For Full System**:\n- Run both backend and frontend profiling\n- Capture end-to-end latencies\n\n**Create Baseline Report**:\n```\n# Performance Baseline\n\n## Backend Metrics\n- Average response time: 250ms (target: 100ms) ⚠\n- 95th percentile response: 800ms (target: 200ms) ⚠\n- Peak memory: 120MB (target: 50MB) ⚠\n- Database query time: 180ms average (target: 50ms) ⚠\n- Cache hit rate: 62% (target: 85%) ⚠\n\n## Frontend Metrics\n- First Contentful Paint: 2.1s (target: 1.5s) ⚠\n- Largest Contentful Paint: 3.2s (target: 2.5s) ⚠\n- JavaScript execution: 450ms (target: 200ms) ⚠\n- Bundle size: 580KB (target: 300KB) ⚠\n\n## Identified Bottlenecks (Priority Order)\n1. Database query in \u002Fapi\u002Flist endpoint (180ms)\n2. JavaScript bundle parsing (150ms)\n3. Form validation on every keystroke (50ms)\n4. Unoptimized images (120KB uncompressed)\n5. Missing indexes on user lookup\n```\n\n### Step 2: Analyze & Prioritize Bottlenecks\n\nFor each bottleneck:\n\n1. **Quantify the impact**\n   - How much time does it consume?\n   - How often does it run?\n   - How many users affected?\n   - What's the cost of not fixing it?\n\n2. **Estimate improvement potential**\n   - What's a realistic target?\n   - How much better could it be?\n   - What's the effort to optimize?\n\n3. **Calculate ROI**\n   - Effort \u002F Time saved = Return on Investment\n   - Prioritize high-ROI items\n\n4. **Group by category**\n   - Database: queries, indexes, N+1 problems\n   - Algorithm: loops, recursion, sorting\n   - Memory: caching, allocation, GC\n   - Network: bundling, compression, parallelization\n   - Frontend: rendering, JavaScript, images\n\nExample prioritization:\n```\nBottleneck | Time | Impact | Effort | ROI | Priority |\n-----------|------|--------|--------|-----|----------|\nDB indexes | 180ms | High | 2h | 90x | 1 |\nBundle split | 150ms | High | 4h | 37x | 2 |\nValidation debounce | 50ms | Low | 1h | 50x | 3 |\nImage optimization | 120ms | Medium | 3h | 40x | 4 |\nCaching | 100ms | Medium | 3h | 33x | 5 |\n```\n\n### Step 3: Plan Optimizations\n\nFor each optimization:\n\n1. **Specify the optimization**\n   - What will change?\n   - Why will it help?\n   - What's the expected improvement?\n\n2. **Plan with TDD**\n   - What tests capture the optimization?\n   - Performance assertion: `assertLatency(operation, maxMs)`\n   - Can you write test before optimization?\n\n3. **Consider trade-offs**\n   - Memory vs. CPU tradeoff\n   - Complexity vs. performance\n   - Maintainability impact\n\n4. **Document approach**\n   - How will it be measured?\n   - How will success be verified?\n   - What's the fallback if it breaks?\n\nExample optimization plan:\n```\n# Optimization 1: Add database index on user_id\n\nBottleneck: User lookup query takes 180ms\nCurrent: SELECT * FROM orders WHERE user_id = ?\n         (full table scan on 1M rows)\n\nOptimization: CREATE INDEX idx_orders_user_id ON orders(user_id)\n\nExpected improvement: 180ms → 5ms (35x faster)\nTrade-offs: Slight write performance impact, +10MB storage\n\nTest plan:\n- test_list_orders_within_performance_budget() (max 50ms)\n- Verify with: pytest test_perf.py::test_list_orders_latency\n\nFallback: Drop index if causes write performance issues\n```\n\n### Step 4: Implement Optimizations with TDD\n\nFor each optimization, follow TDD discipline:\n\n**Step 4a: Write Performance Test**\n\n```python\nimport pytest\nimport time\n\ndef test_list_orders_performance():\n    \"\"\"Orders list should return \u003C 50ms for 1000 orders\"\"\"\n    # Arrange: Create test data\n    user = create_test_user()\n    for i in range(1000):\n        create_test_order(user)\n\n    # Act: Time the operation\n    start = time.perf_counter()\n    orders = get_user_orders(user)\n    duration = time.perf_counter() - start\n\n    # Assert: Verify performance\n    assert duration \u003C 0.050, f\"Got {duration*1000:.1f}ms, target \u003C 50ms\"\n    assert len(orders) == 1000\n```\n\n**Step 4b: Run Test - Verify It Fails**\n\n```bash\npytest test_perf.py::test_list_orders_performance -v\n# FAILED - got 180ms, target 50ms\n```\n\n**Step 4c: Implement Optimization**\n\nFor database index optimization:\n```sql\n-- migrations\u002F001_add_user_index.sql\nCREATE INDEX idx_orders_user_id ON orders(user_id);\n```\n\nFor algorithm optimization:\n```python\n# Before: O(n²) algorithm\ndef find_duplicates(items):\n    duplicates = []\n    for i, item in enumerate(items):\n        for j in range(i+1, len(items)):\n            if items[i] == items[j]:\n                duplicates.append(item)\n    return duplicates\n\n# After: O(n) algorithm\ndef find_duplicates(items):\n    seen = set()\n    duplicates = set()\n    for item in items:\n        if item in seen:\n            duplicates.add(item)\n        seen.add(item)\n    return list(duplicates)\n```\n\nFor bundle optimization:\n```javascript\n\u002F\u002F Before: Single large bundle (580KB)\nimport * as app from '.\u002Fapp.js'; \u002F\u002F all code\n\n\u002F\u002F After: Code splitting\n\u002F\u002F main.js (180KB)\nimport { HomePage } from '.\u002Fpages\u002Fhome.js';\n\u002F\u002F admin.js (150KB) - loaded on demand\n\u002F\u002F reports.js (120KB) - loaded on demand\n```\n\n**Step 4d: Run Test - Verify It Passes**\n\n```bash\npytest test_perf.py::test_list_orders_performance -v\n# PASSED - got 8ms, target 50ms ✓\n```\n\n**Step 4e: Verify No Regression**\n\nRun full test suite to ensure optimization doesn't break anything:\n```bash\nnpm test  # or pytest\n# All tests pass ✓\n```\n\n### Step 5: Measure & Document Results\n\nAfter implementing optimization:\n\n1. **Measure actual improvement**\n   ```\n   Before: 180ms average\n   After: 8ms average\n   Improvement: 95.6% faster (22.5x improvement)\n   Target met: ✓ (8ms \u003C 50ms target)\n   ```\n\n2. **Update performance baseline**\n   - Record new metrics\n   - Compare to targets\n   - Identify next bottleneck\n\n3. **Document in code**\n   ```python\n   def get_user_orders(user_id):\n       \"\"\"Retrieve user's orders.\n\n       Performance: \u003C 10ms (uses index on user_id)\n\n       Note: This uses an indexed query to keep latency low.\n       If you need to add more WHERE clauses, ensure they\n       are also indexed or consider query optimization.\n\n       See: docs\u002Fperformance.md for optimization history\n       \"\"\"\n       return db.query(\n           \"SELECT * FROM orders WHERE user_id = ? ORDER BY created DESC\",\n           [user_id]\n       )\n   ```\n\n4. **Create performance documentation**\n   - Create docs\u002Fperformance.md if not exists\n   - Record optimization history\n   - Document performance targets\n   - Link to profiling data\n\n   ```markdown\n   # Performance Documentation\n\n   ## Performance Targets\n   - Page load time: \u003C 2s\n   - API response: \u003C 100ms (p95)\n   - Bundle size: \u003C 300KB\n\n   ## Optimization History\n\n   ### 2025-02-07: Database Index on user_id\n   - Problem: User orders query took 180ms\n   - Solution: Added index on orders.user_id\n   - Result: Now 8ms (22.5x improvement)\n   - Test: test_list_orders_performance\n   - Status: ✓ Deployed to production\n\n   ### 2025-02-06: Code splitting\n   - Problem: Bundle size 580KB, slow initial load\n   - Solution: Split into main (180KB) + lazy chunks\n   - Result: FCP reduced from 2.1s to 1.2s\n   - Test: test_first_contentful_paint\n   - Status: ✓ Deployed to production\n\n   ## Current Performance Profile\n   - Average API response: 45ms (target: 100ms) ✓\n   - Page load FCP: 1.2s (target: 1.5s) ✓\n   - Bundle size: 280KB (target: 300KB) ✓\n   - Memory peak: 45MB (target: 50MB) ✓\n   ```\n\n## Output Format\n\nUpon completion, output:\n\n```\n# Performance Optimization Complete ✓\n\n## Optimizations Applied\n- Count: {N} optimizations implemented\n- All tests passing: ✓\n\n## Results Summary\n| Optimization | Before | After | Improvement |\n|--------------|--------|-------|-------------|\n| Database query | 180ms | 8ms | 95.6% ↓ |\n| Bundle size | 580KB | 280KB | 51.7% ↓ |\n| Form validation latency | 50ms | 15ms | 70% ↓ |\n\n## Performance Targets Status\n- Page load (FCP): 1.2s (target: 1.5s) ✓\n- API response (p95): 45ms (target: 100ms) ✓\n- Bundle size: 280KB (target: 300KB) ✓\n- Memory peak: 45MB (target: 50MB) ✓\n\n## Scope Optimized\n- Backend: ✓\n- Frontend: ✓\n- Database: ✓\n\n## Tests Updated\n- Performance tests: {count} new tests\n- All tests passing: {count}\u002F{count}\n\n## Documentation\n- Performance profile: docs\u002Fperformance.md\n- Optimization log: [detailed results]\n\n## Next Steps\n1. Review profile and optimization decisions\n2. Run full quality gates: \u002Fadd:verify --level deploy\n3. Deploy to staging and monitor\n4. If all good, deploy to production\n\n## Performance Test Results\n- test_list_orders_performance: PASS (8ms)\n- test_form_validation_latency: PASS (15ms)\n- test_bundle_load_time: PASS (0.8s)\n- test_memory_usage: PASS (45MB)\n```\n\n## Progress Tracking\n\n**Tasks to create** (mechanics per `${CLAUDE_PLUGIN_ROOT}\u002Freferences\u002Fskill-epilogue.md`):\n\n| Phase | Subject | activeForm |\n|-------|---------|------------|\n| Profile | Profiling performance baseline | Profiling performance... |\n| Bottlenecks | Identifying bottlenecks | Identifying bottlenecks... |\n| Optimize | Applying optimizations | Applying optimizations... |\n| Verify | Verifying performance improvements | Verifying improvements... |\n\n## Error Handling\n\n**Performance test not passing after optimization**\n- Review the implementation change\n- Check for unintended side effects\n- Verify profiling methodology\n- Try different optimization approach\n- Revert and try next highest-ROI bottleneck\n\n**Optimization breaks other tests**\n- Performance gained comes at correctness cost (bad)\n- Revert the optimization\n- Find alternative approach\n- Document why that approach won't work\n\n**Unable to reach target**\n- Document realistic achievable target\n- Revisit optimization with different approach\n- Consider if target is unrealistic\n- Flag for architecture review\n\n**Profiling tools not available**\n- Install tools: pip install py-spy, npm install -g lighthouse\n- Or use alternative profilers available\n- Document which tools were used\n\n## Integration with Other Skills\n\n- Used after \u002Fadd:tdd-cycle completes (code is stable)\n- Used before \u002Fadd:deploy to ensure performance requirements met\n- \u002Fadd:verify validates that optimization doesn't break tests\n- Performance tests become part of permanent test suite\n\n## Configuration in .add\u002Fconfig.json\n\n```json\n{\n  \"perf\": {\n    \"pageLoadTime\": 2.0,\n    \"responseTime\": 100,\n    \"memoryLimit\": 50,\n    \"bundleSize\": 300,\n    \"profiler\": \"chrome-devtools\",\n    \"targetPlatforms\": [\"web\", \"mobile\"]\n  }\n}\n```\n\n## Performance Testing Best Practices\n\n1. **Test real scenarios**\n   - Use realistic data volumes\n   - Test with production-like load\n   - Consider network latency (for e2e)\n\n2. **Measure consistently**\n   - Run tests multiple times (warm up JIT)\n   - Use standard hardware for benchmarks\n   - Control for other system activity\n\n3. **Set realistic targets**\n   - Based on business needs\n   - Based on competitive analysis\n   - Based on user experience standards\n\n4. **Monitor regressions**\n   - Keep performance tests in CI\n   - Alert on performance degradation\n   - Compare against baseline\n\n5. **Document trade-offs**\n   - Every optimization has trade-offs\n   - Complexity vs. performance\n   - Memory vs. CPU\n   - Development time vs. speed\n\nEnd-of-skill epilogue: follow `${CLAUDE_PLUGIN_ROOT}\u002Freferences\u002Fskill-epilogue.md` (observation + learning checkpoint + progress tracking).\n",{"references":48,"description":7,"allowed-tools":51,"argument-hint":58},[49,50],"skill-epilogue.md","rules\u002Ftelemetry.md",[52,53,54,55,56,38,57],"Read","Write","Edit","Glob","Grep","Task","[--scope backend|frontend|full] [--profile-first]","main","e335248c85d50f73919320bc138766eb413c5ee3","plugins\u002Fadd\u002Fskills\u002Foptimize",6,"https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd","https:\u002F\u002Fgetadd.dev","https:\u002F\u002Fgithub.com\u002FMountainUnicorn","2026-10-31 22:03:50",{"source":8,"skillName":5,"commands":68,"prompt":78,"zipAvailable":79},[69,72,75],{"tool":70,"command":71},"npx","npx skills add MountainUnicorn\u002Fadd --skill optimize",{"tool":73,"command":74},"bunx","bunx skills add MountainUnicorn\u002Fadd --skill optimize",{"tool":76,"command":77},"pnpm","pnpm dlx skills add MountainUnicorn\u002Fadd --skill optimize","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Fplugins\u002Fadd\u002Fskills\u002Foptimize\u002FSKILL.md",true,[],[82,90,95,100,110,137],{"skillNo":83,"name":84,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":43},"01M6CHXN68ZCGNXE9Q0K2T2RKX","add-verify","https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Ftests\u002Fhooks\u002Ffixtures\u002Fdoctor\u002Fmanifest-modified\u002Fskills\u002Fadd-verify\u002FSKILL.md",[],[88,89],"add verify","verify",{"skillNo":91,"name":84,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":43},"01M6CHXJY4ZXKTNP0235A9KTNH","https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Ftests\u002Fhooks\u002Ffixtures\u002Fdoctor\u002Fmanifest-missing\u002Fskills\u002Fadd-verify\u002FSKILL.md",[],[88,89],{"skillNo":96,"name":84,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":43},"01M6CHXG6NV1DBMWT2N6XE5555","https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Ftests\u002Fhooks\u002Ffixtures\u002Fdoctor\u002Fhealthy\u002Fskills\u002Fadd-verify\u002FSKILL.md",[],[88,89],{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":43},"01M6CHXDZFPEFBZ79GHP48S1BB","version","[ADD v0.11.0] Show installed version, project version, and upgrade status","https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Fplugins\u002Fadd\u002Fskills\u002Fversion\u002FSKILL.md",[],[102,35,107,41,38,36,108,26,29,109],"status","check","show",{"skillNo":111,"name":89,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":124,"publishedAt":43},"01M6CHXB5XG415PP88E0GACHP8","[ADD v0.11.0] Run quality gates — lint, types, tests, coverage, spec compliance","https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Fplugins\u002Fadd\u002Fskills\u002Fverify\u002FSKILL.md",[115,118,119],{"categoryNo":116,"categoryName":117,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000011","运维与部署",{"categoryNo":23,"categoryName":24,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":120,"categoryName":121,"taxonomyType":122,"taxonomyTypeDesc":123},"01JBSEEDCAT000000000000037","律师与法务","PROFESSION","适用职业",[89,35,26,125,30,29,126,127,36,41,128,129,130,131,132,133,134,38,135,136],"coverage","smoke","gate","spec","quality gates","run","lint","ci","compliance","secrets","learning","quality",{"skillNo":138,"name":139,"nameZh":6,"description":140,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":150,"publishedAt":43},"01M6CHX8JF3M3J8BKTBW604D37","ux","[ADD v0.11.0] Iterate on UI\u002FUX design before implementation — wireframes, flow validation, and design sign-off","https:\u002F\u002Fgithub.com\u002FMountainUnicorn\u002Fadd\u002Fblob\u002Fmain\u002Fplugins\u002Fadd\u002Fskills\u002Fux\u002FSKILL.md",[143,146,147],{"categoryNo":144,"categoryName":145,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000015","视觉设计",{"categoryNo":23,"categoryName":24,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":148,"categoryName":149,"taxonomyType":122,"taxonomyTypeDesc":123},"01JBSEEDCAT000000000000032","设计师",[139,151,152,153,154,41,128,38,155,36,35,26,33,32,29,156,157,158,159],"ui","file","figma","validation","system","design-system","implementation","flow","design"]