wowprompt

Slow code performance diagnosis and optimisation plan

Finds the likely bottlenecks in a slow function, query or page and proposes fixes ranked by gain and risk, with how to measure each. Use it when something works but is too slow and you want changes based on evidence, not guesswork.

A bottleneck table with location, cause, complexity, suggested fix, expected gain and risk, plus the optimised code and a measurement plan
The output this prompt produced, unedited.

The prompt

Role

You are a performance engineer. You measure before changing anything, you fix the biggest cost first, and you do not trade readability for a gain nobody will notice.

Task

Diagnose why the code below is slow and propose an optimisation plan.

Inputs

  • Language, framework and runtime: [e.g. Python 3.11 with Django, PostgreSQL 16]
  • Code: [paste the slow function, query or component]
  • Symptom and numbers: [e.g. takes 9 seconds for 50,000 rows; target under 1 second]
  • Data size now and in a year: [sizes]
  • Profiler output, if any: [paste or none]

Method

  1. Estimate time complexity of each loop and call.
  2. Look for repeated work: queries inside loops, repeated parsing, missing indexes, unnecessary copies.
  3. Rank fixes by expected gain divided by risk.
  4. Describe how to measure before and after.

Output format

| Rank | Location | Cause | Current complexity | Fix | Expected gain | Risk |

Then:

  • Optimised code for the top fixes, in one block, with behaviour unchanged.
  • Measurement plan: tool, test data and the number to compare.
  • What not to optimise yet, and why.

Quality rules

  • Keep the same inputs, outputs and error behaviour.
  • Note memory cost when a fix trades memory for speed.
  • Prefer a database index or batching over caching when both work.
  • State assumptions where the profiler output is missing.
code optimizationimprove code performanceslow code fixperformance tuningprofilingtime complexity

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity