Analyze code for performance issues including N+1 queries, unnecessary re-renders, memory leaks, and bundle impact.
Fill in this template
The {{ }} placeholders are variables — drop in your own details, then copy the ready-to-use prompt. (Or copy the template as-is and let your AI assistant fill them in.)
0/2 filled
Preview filled prompt
You are a performance engineering specialist. Review this code for performance issues.
## Code to Review
```
{{CODE}}
```
## Context
{{CONTEXT}}
## Performance Analysis Dimensions
### 1. Data Fetching & Queries
- **N+1 queries**: Are there loops that trigger individual database queries? Should they be batched?
- **Over-fetching**: Are queries selecting more columns or rows than needed?
- **Missing indexes**: Based on the query patterns, are there likely missing database indexes?
- **Connection management**: Are database connections properly pooled and released?
### 2. Rendering & UI (if applicable)
- **Unnecessary re-renders**: Are components re-rendering when their props haven't changed?
- **Missing memoization**: Should React.memo, useMemo, or useCallback be applied?
- **Large lists**: Should virtualization (react-window, react-virtuoso) be used?
- **Layout thrashing**: Are DOM reads and writes interleaved in loops?
### 3. Memory
- **Leaks**: Are event listeners, subscriptions, or timers cleaned up?
- **Unbounded growth**: Are arrays, maps, or caches growing without limits?
- **Closures**: Are closures inadvertently holding references to large objects?
- **Circular references**: Could garbage collection be prevented?
### 4. Bundle & Load Time
- **Code splitting**: Are large dependencies lazily loaded?
- **Tree shaking**: Are imports barrel-file imports that defeat tree shaking?
- **Asset optimization**: Are images, fonts, and other assets optimized?
### 5. Algorithm & Complexity
- **Time complexity**: Are there O(n^2) or worse algorithms that could be O(n) or O(n log n)?
- **Unnecessary work**: Are computations repeated that could be cached?
- **Async patterns**: Are independent async operations run in parallel (Promise.all) instead of sequentially?
## Output Format
For each issue found:
- **Category — Severity (Critical/High/Medium/Low)**: Description
- Impact: estimated performance effect (e.g., "adds ~200ms per 1000 records")
- Current code: quote the problematic section
- Optimized code: provide the fix
End with a prioritized list of top 3 optimizations ranked by expected impact.Tags
performanceoptimizationcode-reviewprofiling
Related
Explore more prompts and rules
BeforeMerge offers hundreds of AI prompts, code review rules, guides, and detection patterns to help your team ship better code.