Performance Optimization

A measure-first optimization loop: profile under real load, rank by Amdahl math, change one thing, re-measure, no speculative micro-tuning.

Help me make this faster, with discipline. Rule zero: no optimization gets proposed until we've seen a measurement that implicates it.

What's slow: [THE SYMPTOM + NUMBERS: "the /reports endpoint takes 8s p95" / "this script takes 40 min on 1M rows"]
The target: [WHAT FAST ENOUGH MEANS: "p95 under 1s" / "under 5 min", no target, no finish line]
Stack: [LANGUAGE/RUNTIME + FRAMEWORK + WHERE IT RUNS]
What I have so far: [PROFILER OUTPUT / FLAME GRAPH / SLOW-QUERY LOG / APM TRACE, paste it. If nothing: say so and start at step 1.]
The code (the suspected hot path, if known):
"""
[PASTE, or let an agent explore]
"""

Work the loop:
1. **Get the measurement first**: if I haven't profiled: the exact profiling command for my stack (py-spy/cProfile for Python, clinic.js or --prof for Node, pprof for Go, async-profiler for JVM, EXPLAIN ANALYZE for SQL) and how to run it under representative load; profiling an idle path finds nothing. Distinguish on-CPU from off-CPU time: high wall-time with low CPU means we're WAITING (I/O, locks, queries), not computing; different profiler, different fixes.
2. **Read the profile**: identify the top consumers by time share. Check the classic wastes against the evidence: N+1 queries, synchronous I/O in the hot path, per-item network/DB calls that should batch, allocation churn, repeated computation, missing index behind an ORM call.
3. **Rank by Amdahl math**: for each candidate: its share of total time × plausible speedup = ceiling on overall gain. Say the numbers out loud ("this function is 6% of runtime; a perfect fix saves 6%"). This kills the tempting-but-irrelevant micro-optimizations before they eat a day.
4. **One change**: the top-ranked fix, implemented minimally. State the predicted improvement.
5. **Re-measure the same workload**: before/after numbers, p50 AND p95/p99 (means hide tail pain). Keep or revert on evidence. Then loop, or stop, because:
6. **Stop at the target**: once the stated target is met, remaining "slowness" is a non-problem. List the further optimizations NOT taken and why (cost/complexity vs. gain below target): restraint documented is restraint defended.

Benchmark discipline throughout: warm-up runs before timing (JIT, caches), multiple iterations with variance noted, same data and environment across comparisons; a benchmark that changed two variables measured nothing.

Rules: refuse micro-optimizations the profile doesn't implicate, readability outranks speculative speed outside the measured hot path. If the profile shows the bottleneck is architectural (chatty service calls, missing cache layer), say that honestly instead of polishing code around it.
Originated fromStan SedberryUpdated
Debuggingadvanced

More coding prompts

Write the commit message for this change.

Diff:
"""
[PASTE THE STAGED DIFF]
"""

Why I made this change: [THE REASON, THE TICKET, THE BUG REPORT, or "you infer it"]
Convention: [Conventional Commits / this repo's existing style, pasted below / plain]
Recent commits from this repo, to match style:
"""
[PASTE 5-10 RECENT COMMIT SUBJECT LIN

Commit Message

Write a commit message that explains why the change was made, in Conventional Commits format, split into separate commits when needed.

Codingbeginner
Help me recover from a git mistake without making it worse.

What I was trying to do: [THE GOAL]
What I ran: [THE EXACT COMMANDS, IN ORDER]
What happened instead: [THE OUTPUT OR THE STATE NOW]
Has this been pushed or shared: [YES/NO, and to which branch and whether anyone else has pulled]
Uncommitted work I cannot lose: [WHAT AND WHERE, o

Undo a Git Mistake

Recover from a bad commit, force push, wrong branch, or lost work with a reversible plan and the exact commands, explained before you run them.

Codingintermediate
Handler code, routes, and models:
"""
[PASTE THE ROUTE DEFINITIONS, HANDLERS, REQUEST AND RESPONSE TYPES, VALIDATION SCHEMAS, AND MIDDLEWARE]
"""

Generate an OpenAPI 3.1 specification from the code above.

API name, version, and base URL: [DETAILS]
Auth scheme: [BEARER JWT / API KEY / OAUTH / SESSION COOKIE, and where it is enforced]
Con

OpenAPI Spec From Code

Generate an accurate OpenAPI 3.1 spec from handler code, including error responses and auth, with gaps flagged instead of invented.

Codingintermediate

Search prompts

Find a prompt by title, description, tag, or category.