
- Updated
Speed up a slow API endpoint or function
This prompt works like a performance review: it finds the biggest slowdowns first, estimates what each one costs, and shows the fix. Paste the code, the queries it runs and real timing numbers if you have them.
Act as a performance engineer. This [ENDPOINT OR FUNCTION, e.g. GET /orders] takes [TIME, e.g. 4 seconds] and should take under [TARGET, e.g. 300 ms]. Code: [PASTE] Database queries or ORM calls it makes: [PASTE OR DESCRIBE] Data size: [e.g. 200k orders, 5k users] Find the biggest slowdowns first (N+1 queries, missing indexes, loops inside loops, repeated work, large payloads). For each, estimate how much time it costs, show the fix, and tell me how to measure before and after. Change only what gives a real gain.
Paste real timing numbers or a profiler output if you have them. Guesses about performance are often wrong.
Get a better result
The biggest slowdowns in your endpoint ranked by cost, such as N+1 queries, missing indexes or repeated work, with an estimate of the time each one costs, the fix, and how to measure before and after.
Giving the current time and the target turns a vague “make it faster” into a goal the model can plan around. The data size matters, because a loop that is fine over a hundred rows is the bottleneck at two hundred thousand. Asking for the biggest gains first and “change only what gives a real gain” keeps it from rewriting code that was never the problem.
It adds caching before fixing the slow query.
Fix: Ask it to fix the query first and add a cache only if the endpoint is still above your target after that.
- The time estimates are guesses. Paste real timings or a query log, as the tip says, and ask it to work from those numbers.
- The fix changes what the endpoint returns. Ask it to keep the response the same and to list any field it had to change, so clients do not break.
Ask what happens to this endpoint at ten times today’s traffic, and which fix to make now so it stays under your target.
I applied the first fix. Here are the new timings: [PASTE]. What is the next biggest cost, and is it worth fixing?
More chat & writing prompts
See all 465 →More like this
- Write API documentation from codeChatGPT · Gemini · Claude
- Design a REST API for your appChatGPT · Gemini · Claude
- Plan how to find a performance bottleneckChatGPT · Gemini · Claude
- Understand a long SQL query step by stepClaude · ChatGPT · Gemini
- Add an AI feature to your app with an LLM APIClaude · ChatGPT · Gemini



