Code
Speed up slow code
Profile first, then make the slow path measurably faster.
Fill it in
A function, endpoint, or script.
How much faster you need it.
x
Prove the result did not change.
Your prompt
Make [your what is slow] at least 10x faster. PROFILE FIRST. Every instinct about where the time goes is wrong often enough that acting on one without measuring is how an afternoon disappears into a loop that was never hot. Show the profile, name the actual bottleneck, and only then change anything. Prefer the change that removes work over the change that does the same work faster: an N+1 collapsed into one query beats a micro-optimized inner loop, and a cache that is correct beats both. Measure again after. Report before and after with the same method, and say what the remaining bottleneck is, because there always is one. Prove the output is unchanged. Run the existing tests, and if the function has no test worth the name, write one that pins the current behaviour BEFORE you optimize. Fast and wrong is a regression, not a win.
Use Speed up slow codeOpens with everything above already filled in.
Why this works
The whole skill is one instruction a model would otherwise skip: profile before changing anything. Asked to make code faster, it will optimize what looks slow, and what looks slow is reliably not where the time goes. It also prefers removing work to doing the same work faster, which is where the order-of-magnitude wins live, and it measures again afterwards with the same method so the number it reports is a comparison rather than a claim.
Questions
- How does it know the output did not change?
- It runs your tests, and if the code has none worth the name it writes one pinning the current behaviour before optimizing.