Coding
AI Prompt for Performance Review
Review code for performance with this AI prompt: spot slow patterns, estimate Big-O impact, and get an optimized rewrite that keeps behavior identical.
The prompt
Role: You are a performance-obsessed engineer reviewing code for speed and efficiency problems. Context: Language: [LANGUAGE], environment: [ENVIRONMENT: browser / server / mobile]. The slow part: [CODE_SNIPPET]. Measured symptom: [SYMPTOM, e.g. 2s render for 500 rows, API p99 800ms]. Task: 1) Identify performance anti-patterns in this code (nested loops, repeated work, unnecessary allocations, blocking calls, n+1 queries, layout thrash — whatever applies). 2) For each, estimate the complexity impact in plain terms (e.g. "this makes rendering O(n^2)"). 3) Provide an optimized rewrite with identical behavior. 4) Note any trade-offs (memory vs speed, readability vs speed) and when the optimization is NOT worth it. Format: Findings ranked by expected impact, each with the problem, the complexity note, and the fixed code. End with the trade-off notes. Finally, ask for a measurement plan: which benchmark or profiler metric would prove each optimization worked, and what result would make you revert it. Optimizations without success criteria tend to become permanent complexity. Constraints: Do not sacrifice correctness for speed. Do not suggest premature micro-optimizations — focus on algorithmic and structural wins first.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[LANGUAGE] [ENVIRONMENT] [CODE_SNIPPET] [SYMPTOM]
Example input
LANGUAGE=JavaScript, CONTEXT=React product listing page, SYMPTOM=page janks when scrolling 500 items, HOTSPOT=render loop with inline object creation
How to use this prompt
Point at the slow part — full-file reviews find style issues, not hotspots. Include any timing numbers you have; they tell the AI where the pain really is.
Tips for the best results
- Always profile first and paste the numbers — the AI optimizes what you point it at.
- Ask it to estimate the expected speedup so to decide if the change is worth the risk.
- Have it re-verify the optimized code produces identical outputs on your test cases.
Frequently asked questions
Can it find performance issues without benchmarks?
It finds algorithmic and structural issues (n+1 queries, accidental re-renders, O(n^2) loops). Confirm with a profiler before optimizing.
What if I have no profiler data yet?
Then say so — it will focus on correctness-preserving micro-optimizations and ask for the profiler data to verify.