Coding Workflows Workflow Advanced

AI Performance Optimization Workflow

Speed up code that works but drags — find the actual hot path instead of guessing, understand why it's slow, optimize it, and prove with tests that you changed the speed and nothing else.

The problem

Optimizing on instinct is how you spend a day speeding up a function that wasn't the problem. Performance work has a discipline: find where the time actually goes before touching anything, understand why that spot is slow, change it, and prove you changed only the speed. The trap sits on both ends — guessing at the bottleneck, and guessing that the optimization didn't quietly change a result. This workflow replaces both guesses with evidence.

Recommended workflow

Each step uses an existing NewPrompt tool, pre-filled by a matching resource. Open the resource to read it, or jump straight into the tool with the inputs ready.

  1. Find the real bottleneck

    Before optimizing, locate where the time actually goes — the hot loop, the N+1 query, the redundant recompute. Optimizing the wrong spot is the most common way performance work wastes a day.

    Outcome The actual hot path, identified with evidence, not a hunch.
  2. Understand why it's slow

    Get a clear read of what the slow code does and why it's expensive, so the optimization addresses the cause — an algorithm, a data structure, a repeated call — instead of papering over the symptom.

    Outcome A grounded understanding of the cause of the slowness.
  3. Optimize the hot path

    Make the targeted change — a better algorithm, caching, fewer passes — keeping behavior identical. Faster code that returns a different answer is a regression, not an optimization.

    Outcome A faster implementation with behavior preserved.
  4. Prove speed changed and behavior didn't

    Back the change with tests that confirm the same inputs still produce the same outputs, so the win is real speed and not a silently altered result.

    Outcome Tests proving the optimization preserved behavior.

Expected outcome

The real bottleneck is found, understood, and optimized, with tests confirming the behavior is unchanged — a measurable speedup you can trust, instead of a faster function that quietly returns something different.

Best for

  • Speeding up correct-but-slow code
  • Fixing a performance bottleneck without changing behavior
  • Optimizing a hot path you've already located

Not for

  • Fixing a bug — the code here works, it's just slow; use the AI Debugging Workflow
  • Restructuring for readability with no speed goal — use the AI Refactoring Workflow
  • Tuning database queries specifically — that's a SQL-focused job

FAQ

AI performance optimization workflow vs AI debugging workflow?

The debugging workflow fixes code that returns the wrong result; this one speeds up code that's already correct but slow. Its success condition is a measurable speedup with identical behavior, proven by step 4's regression tests. Debugging changes the output on purpose; this workflow must never change it.

Why find the bottleneck before optimizing?

Because most of the time concentrates in a small fraction of the code, and optimizing anywhere else is wasted effort that adds complexity for no gain. Locating the hot path first is what makes the optimization worth doing.

What does the AI performance optimization workflow produce?

You end with the real bottleneck located with evidence, a grounded read of why it's slow, a faster implementation of that hot path, and tests proving the same inputs still return the same outputs. NewPrompt supplies the prompts and step order; you run them and own the measured result.

How do I run the AI performance optimization workflow?

Work the four steps in order in your own AI tool: use the debugging-prompt-generator to find the hot path, the code-explanation-prompt to understand why it's slow, the refactor-prompt-builder to optimize it, then the test-case-prompt-generator to verify behavior. NewPrompt hands you the prompts; you run each one and review the code.

What do I need before starting the performance optimization workflow?

Bring code that already works and a concrete sign it's too slow — a lagging endpoint, a heavy loop, a slow page. Step 1 finds where the time actually goes, so you don't need to know the bottleneck yet, but you do need the correct-but-slow code in front of you.

How do I verify the optimization didn't cause a regression?

Step 4 backs the change with tests confirming the same inputs still produce the same outputs, so the win is real speed and not a silently altered result. AI drafts the tests and helps you compare — but you run them and make the final call that behavior held.

Part of these projects

Complete build journeys that include this workflow as a stage.

Guides for this workflow

Recommended next workflow

Tip: Each step's resource opens its tool pre-filled — start at step one and carry the output forward.