Speed up slow code
Finds performance bottlenecks and suggests faster approaches with measurable trade-offs.
The prompt
Help me make this code faster.
Language/runtime: [DETAILS]
Code:
[PASTE]
What's slow and how I measured it: [timings, profiler output, data sizes]
Constraints: [memory, readability, can't change interface]
Deliver:
1. Likely bottlenecks, with the reasoning (complexity, I/O, allocations, N+1 queries, etc.).
2. Optimizations ranked by expected gain vs. effort, with code for the top ones.
3. How to benchmark before and after to confirm the gain.
4. Trade-offs introduced (readability, memory, correctness risks).
Don't micro-optimize at the cost of clarity unless the gain is significant.
Highlighted [brackets] are blanks to replace with your own details.
Fill in the blanks and use this promptMore Software Development prompts
What to fill in
- DETAILS
- PASTE
- timings, profiler output, data sizes
- memory, readability, can't change interface
How this prompt is built
This prompt follows the RTF structure (Role, Task, Format). RTF tells the model who to be, what to do and what shape the answer should take. It is the quickest structure that still gives noticeably better results than a bare request.
Related prompts
- Explain what a piece of code doesPlain-language walkthrough of unfamiliar code: purpose, flow, key parts, and gotchas.
- Convert code to another language or frameworkIdiomatic translation of code between languages or frameworks, with notes on differences.
- Write unit tests for my codeComprehensive unit tests covering happy paths, edge cases, and failures.
- Design input validation rules for my appConsistent validation rules for every input across client, server, and database, with security checks, error messages, and tests.