Profile and Fix Performance Bottlenecks
Analyze code for performance issues, identify the slowest paths, and get optimized solutions.
The Prompt
Analyze the following code for performance bottlenecks. Provide: 1. Identified bottlenecks in order of impact 2. Why each one is slow (theoretical explanation) 3. How to profile/measure it in practice (specific profiling commands or tools) 4. The optimized implementation 5. Expected performance improvement (rough estimate) Performance context: - Expected input size: [e.g., 10,000 items, 50 concurrent users] - Current observed behavior: [e.g., API takes 3-4 seconds for requests with >1000 items] - Language/runtime: [NODE.JS / PYTHON / GO / etc.] Code to profile: ``` [PASTE YOUR CODE] ```
Example Output
Identified 3 bottlenecks: synchronous file reads inside a loop (fix: Promise.all for parallelism), re-computing a regex on every iteration (fix: compile once outside the loop), and an O(n²) deduplication approach (fix: Set-based O(n) approach). Estimated 15x combined speedup.
FAQ
Which AI model is best for Profile and Fix Performance Bottlenecks?
Claude Sonnet 4 or o4-mini — both reason well about performance characteristics.
How do I use the Profile and Fix Performance Bottlenecks prompt?
Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Identified 3 bottlenecks: synchronous file reads inside a loop (fix: Promise.all for parallelism), re-computing a regex on every iteration (fix: compile once outside the loop), and an O(n²) deduplication approach (fix: Set-based O(n) approach). Estimated 15x combined speedup.
Model Recommendation
Claude Sonnet 4 or o4-mini — both reason well about performance characteristics.