AgentSkillsCN

performance-audit

当用户提及“慢”“性能”“优化”“速度”“延迟”“加载”“内存”“CPU”,或希望让某项功能运行得更快时,此技能可提供性能分析框架。

SKILL.md
--- frontmatter
name: performance-audit
description: When the user mentions "slow", "performance", "optimize", "speed", "lag", "loading", "memory", "CPU", or asks to make something faster. Provides performance analysis framework.

Performance Audit Framework

Initial Assessment Questions

  1. What's slow? - Page load, API response, build time, runtime
  2. How slow? - Quantify: 3s vs 30s matters
  3. Baseline? - What's acceptable performance?
  4. When? - Always slow, or under certain conditions?
  5. Where? - Client, server, network, database?

Measurement First

NEVER optimize without measuring. Identify bottlenecks before fixing.

Web Performance Metrics

  • LCP (Largest Contentful Paint) - Main content visible
  • FID (First Input Delay) - Interactivity
  • CLS (Cumulative Layout Shift) - Visual stability
  • TTFB (Time to First Byte) - Server response

Tools

  • Chrome DevTools Performance tab
  • Lighthouse audit
  • WebPageTest.org
  • React DevTools Profiler
  • console.time() / console.timeEnd()

Common Performance Issues

Frontend

IssueDetectionFix
Large bundleWebpack analyzerCode splitting, tree shaking
Render blockingNetwork waterfallDefer/async scripts, critical CSS
Excessive re-rendersReact ProfileruseMemo, useCallback, React.memo
Memory leakMemory timelineCleanup effects, remove listeners
Layout thrashingPerformance timelineBatch DOM reads/writes

Backend/API

IssueDetectionFix
N+1 queriesQuery logsEager loading, batching
Missing indexesEXPLAIN plansAdd appropriate indexes
No cachingRepeated queriesRedis, in-memory cache
Sync blockingFlame graphsAsync/await, worker threads
Large payloadsNetwork tabPagination, field selection

Database

IssueDetectionFix
Full table scanEXPLAINAdd index on filter columns
Too many indexesWrite latencyRemove unused indexes
Large result setsMemory usagePagination, streaming
Lock contentionDeadlock logsOptimize transactions

Quick Wins Checklist

Frontend:

  • Enable gzip/brotli compression
  • Set cache headers
  • Lazy load images and routes
  • Use production builds
  • Minimize third-party scripts

Backend:

  • Add database indexes for common queries
  • Implement response caching
  • Use connection pooling
  • Enable query result caching
  • Optimize N+1 queries

Performance Budget

Set limits and enforce:

  • Bundle size: < 200KB (gzipped)
  • API response: < 200ms (p95)
  • Page load: < 3s (LCP)
  • Build time: < 60s

Output Format

When reporting:

  1. Current State - Measured performance with numbers
  2. Bottlenecks - Identified issues ranked by impact
  3. Recommendations - Specific fixes with expected improvement
  4. Priority - Quick wins vs larger refactors