Coding
AI Prompt for Code Performance Audit
Optimize slow code with this AI prompt: bottleneck audit ranked by impact, optimized rewrite preserving behavior, and benchmarks proving the speedup.
The prompt
Role: You are a performance engineer who optimizes code methodically: measure, find the bottleneck, fix the biggest win first. Context: Language: [LANGUAGE]. The slow code: [CODE]. Measured symptom: [SYMPTOM, e.g. 45s for 100k rows]. Target: [TARGET]. Environment: [ENVIRONMENT]. Task: 1) Audit for performance issues by category: algorithmic complexity, I/O patterns (N+1, sync-in-loop), allocations, string building, redundant work, wrong data structures. 2) Rank findings by EXPECTED IMPACT with reasoning. 3) Provide the optimized code addressing the top findings. 4) Suggest the benchmark to prove the improvement (what to measure, how). 5) State what you deliberately did NOT optimize and why (readability cost, tiny gain). Format: Audit findings ranked by impact, then optimized code, then the benchmark design, then the explicitly-skipped list. Ask the AI to set a performance budget for the optimized code: the maximum acceptable runtime at your data size, enforced by a benchmark in CI. Optimizations decay without guardrails. Constraints: Fix the bottleneck, not random lines — the ranking enforces this. Preserve behavior exactly. No optimization without a measurement plan to verify it.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[LANGUAGE] [CODE] [SYMPTOM] [TARGET] [ENVIRONMENT]
Example input
LANGUAGE=Python, CODE=report generation: loops over 100k rows, queries DB per row, builds string with +=, SYMPTOM=45s runtime, TARGET=<5s
How to use this prompt
Include the measured symptom and target — optimization without a goal is endless. Point at the slow code; audits work best on hotspots, not whole codebases.
Tips for the best results
- Measure before and after with the suggested benchmark — never trust optimization by feel.
- Ask for the impact ranking; developers chronically optimize the wrong 10%.
- Read the skipped list — it teaches optimization judgment.
Frequently asked questions
Where do I start optimizing?
It audits systematically (algorithm → I/O → allocations) and ranks fixes by expected impact — then tells you what to measure to confirm.
Should I optimize before I have users?
Fix algorithmic howlers early, micro-optimize later. The prompt ranks by impact so you never gold-plate code nobody runs.