Performance Audit
Analyze the codebase for performance bottlenecks and optimization opportunities.
Instructions
Conduct a comprehensive performance audit following these steps:
Technology Stack Analysis
- Identify the primary language, framework, and runtime
- Review build tools and optimization configurations
- Check for existing performance monitoring (APM, profilers, dashboards)
Code Performance Analysis
- Identify inefficient algorithms and data structures (especially O(n^2) or worse)
- Look for unnecessary computations, redundant operations, and hot loops
- Review memory allocation patterns and potential leaks
- Run stack-specific profiling:
- Node.js:
node --prof app.js then node --prof-process
- Python:
python -m cProfile -o output.prof script.py
- Go:
go tool pprof http://localhost:6060/debug/pprof/profile
- Rust:
cargo flamegraph
- Java:
jcmd <pid> JFR.start duration=60s filename=profile.jfr
Database Performance
- Analyze queries for efficiency. Run
EXPLAIN ANALYZE on slow or suspicious queries
- Check for missing indexes: look at
WHERE, JOIN, and ORDER BY columns
- Identify N+1 query problems and excessive round-trips
- Review connection pooling settings and pool utilization
- Check for table locks, deadlocks, and long-running transactions
Frontend Performance (if applicable)
- Run
npx lighthouse --output=json --output-path=./report.json <url> to audit Core Web Vitals
- Analyze bundle size:
npx webpack-bundle-analyzer stats.json or npx vite-bundle-visualizer
- Check for unused code and heavy dependencies (
npx depcheck)
- Review render performance: unnecessary re-renders, missing memoization, layout thrashing
- Check image optimization and lazy loading
Network Performance
- Review API call patterns and identify redundant or waterfall requests
- Check caching strategy: HTTP cache headers, CDN configuration, application-level caching
- Analyze payload sizes and verify compression (gzip/brotli) is enabled
- Look for missing pagination on large data sets
Asynchronous Operations
- Review async/await usage for accidental serialization of independent operations
- Check for blocking operations on the main thread or event loop
- Identify opportunities for parallel execution (
Promise.all, goroutine fan-out, etc.)
- Analyze task queue and background job performance
Memory Usage
- Check for memory leaks: growing heap over time, unclosed resources, listener accumulation
- Review garbage collection pressure and large object allocation
- Identify excessive data retention (caches without TTL, unbounded buffers)
- Profile with:
node --inspect (Chrome DevTools), valgrind, go tool pprof /heap
Build and Deployment Performance
- Measure build times and identify slow steps
- Check tree shaking, code splitting, and dead code elimination
- Verify dev vs. production optimization flags
- Review Docker image sizes and layer caching
Performance Monitoring
- Check existing metrics and alerting coverage
- Identify key KPIs: p50/p95/p99 latency, throughput, error rate, saturation
- Suggest missing instrumentation points
Benchmarking and Profiling
- Create benchmarks for critical code paths
- Measure before and after for any proposed optimization
- Document performance baselines for future comparison
Optimization Recommendations
- Prioritize by impact and effort using the severity format below
- Provide specific code changes, not just descriptions
- Suggest architectural improvements for long-term scalability
Output Format
Rate each finding by severity:
### [CRITICAL] N+1 query in OrderService.getAll()
**File:** `src/services/order-service.ts:45`
**Impact:** ~200ms added per request; 2000 extra DB queries under load
**Fix:** Eager-load line items with a JOIN or `include` clause
**Effort:** Low (1-2 hours)
### [HIGH] Uncompressed API responses
**File:** `src/server.ts` (missing middleware)
**Impact:** 3x larger payloads, ~150ms extra on mobile
**Fix:** Add `compression()` middleware
**Effort:** Low (15 minutes)
### [MEDIUM] Synchronous file reads at startup
**File:** `src/config/loader.ts:12`
**Impact:** Adds 400ms to cold start
**Fix:** Switch to async reads or cache after first load
**Effort:** Low (30 minutes)
Severity levels:
- CRITICAL - Causes outages, timeouts, or order-of-magnitude slowdowns under real load
- HIGH - Noticeable user-facing latency or significant resource waste
- MEDIUM - Measurable but tolerable; worth fixing in normal development
- LOW - Minor inefficiency; fix opportunistically
Follow-Up
For load testing and validating fixes under realistic traffic, use the /k6 skill to generate and run load test scripts.
1---2name: performance-audit3description: Analyze codebase for performance bottlenecks across code, database, frontend, network, and async operations4---56# Performance Audit78Analyze the codebase for performance bottlenecks and optimization opportunities.910## Instructions1112Conduct a comprehensive performance audit following these steps:13141. **Technology Stack Analysis**15 - Identify the primary language, framework, and runtime16 - Review build tools and optimization configurations17 - Check for existing performance monitoring (APM, profilers, dashboards)18192. **Code Performance Analysis**20 - Identify inefficient algorithms and data structures (especially O(n^2) or worse)21 - Look for unnecessary computations, redundant operations, and hot loops22 - Review memory allocation patterns and potential leaks23 - Run stack-specific profiling:24 - **Node.js:** `node --prof app.js` then `node --prof-process`25 - **Python:** `python -m cProfile -o output.prof script.py`26 - **Go:** `go tool pprof http://localhost:6060/debug/pprof/profile`27 - **Rust:** `cargo flamegraph`28 - **Java:** `jcmd <pid> JFR.start duration=60s filename=profile.jfr`29303. **Database Performance**31 - Analyze queries for efficiency. Run `EXPLAIN ANALYZE` on slow or suspicious queries32 - Check for missing indexes: look at `WHERE`, `JOIN`, and `ORDER BY` columns33 - Identify N+1 query problems and excessive round-trips34 - Review connection pooling settings and pool utilization35 - Check for table locks, deadlocks, and long-running transactions36374. **Frontend Performance (if applicable)**38 - Run `npx lighthouse --output=json --output-path=./report.json <url>` to audit Core Web Vitals39 - Analyze bundle size: `npx webpack-bundle-analyzer stats.json` or `npx vite-bundle-visualizer`40 - Check for unused code and heavy dependencies (`npx depcheck`)41 - Review render performance: unnecessary re-renders, missing memoization, layout thrashing42 - Check image optimization and lazy loading43445. **Network Performance**45 - Review API call patterns and identify redundant or waterfall requests46 - Check caching strategy: HTTP cache headers, CDN configuration, application-level caching47 - Analyze payload sizes and verify compression (gzip/brotli) is enabled48 - Look for missing pagination on large data sets49506. **Asynchronous Operations**51 - Review async/await usage for accidental serialization of independent operations52 - Check for blocking operations on the main thread or event loop53 - Identify opportunities for parallel execution (`Promise.all`, goroutine fan-out, etc.)54 - Analyze task queue and background job performance55567. **Memory Usage**57 - Check for memory leaks: growing heap over time, unclosed resources, listener accumulation58 - Review garbage collection pressure and large object allocation59 - Identify excessive data retention (caches without TTL, unbounded buffers)60 - Profile with: `node --inspect` (Chrome DevTools), `valgrind`, `go tool pprof /heap`61628. **Build and Deployment Performance**63 - Measure build times and identify slow steps64 - Check tree shaking, code splitting, and dead code elimination65 - Verify dev vs. production optimization flags66 - Review Docker image sizes and layer caching67689. **Performance Monitoring**69 - Check existing metrics and alerting coverage70 - Identify key KPIs: p50/p95/p99 latency, throughput, error rate, saturation71 - Suggest missing instrumentation points727310. **Benchmarking and Profiling**74 - Create benchmarks for critical code paths75 - Measure before and after for any proposed optimization76 - Document performance baselines for future comparison777811. **Optimization Recommendations**79 - Prioritize by impact and effort using the severity format below80 - Provide specific code changes, not just descriptions81 - Suggest architectural improvements for long-term scalability8283## Output Format8485Rate each finding by severity:8687```markdown88### [CRITICAL] N+1 query in OrderService.getAll()89**File:** `src/services/order-service.ts:45`90**Impact:** ~200ms added per request; 2000 extra DB queries under load91**Fix:** Eager-load line items with a JOIN or `include` clause92**Effort:** Low (1-2 hours)9394### [HIGH] Uncompressed API responses95**File:** `src/server.ts` (missing middleware)96**Impact:** 3x larger payloads, ~150ms extra on mobile97**Fix:** Add `compression()` middleware98**Effort:** Low (15 minutes)99100### [MEDIUM] Synchronous file reads at startup101**File:** `src/config/loader.ts:12`102**Impact:** Adds 400ms to cold start103**Fix:** Switch to async reads or cache after first load104**Effort:** Low (30 minutes)105```106107Severity levels:108- **CRITICAL** - Causes outages, timeouts, or order-of-magnitude slowdowns under real load109- **HIGH** - Noticeable user-facing latency or significant resource waste110- **MEDIUM** - Measurable but tolerable; worth fixing in normal development111- **LOW** - Minor inefficiency; fix opportunistically112113## Follow-Up114115For load testing and validating fixes under realistic traffic, use the `/k6` skill to generate and run load test scripts.