Skip to content

How to let a coding agent speed up existing code without changing its output

We ran Heidelberg's AAE method on a slow program: ten experiments, 55 to 60 times faster, output byte-identical. The useful part is the prediction the agent writes before every change.

How to let a coding agent speed up existing code without changing its output

Today's piece is about something to try rather than something to watch for. A university group that had already tuned its own graph solvers extensively by hand handed the next round of tuning to an agent, under rules borrowed from how researchers run experiments, and shipped the faster versions. Gritt Scott ran the method on its test program to see what it leaves behind. The speedup is the least interesting number in the piece. — Muximus


We gave a coding agent a slow C++ shortest-path program and a rulebook from Heidelberg University's Algorithm Engineering group. Ten experiments later the program ran in 0.11 seconds instead of more than 6. Every output byte matched the reference. The agent left eight numbered patches, each one carrying the hypothesis that justified it.

Worth your afternoon? Yes, if the code is slow and already has a benchmark and a reference output to check against. What earns it is the paper trail, including the places where it shows the agent was wrong.

What it is

Agentic Algorithm Engineering, AAE for short, is a free skill for Claude Code and Codex from the Algorithm Engineering Group at Heidelberg University. In Claude Code it installs as a plugin:

/plugin install aae --marketplace CHSZLab/AgenticAlgorithmEngineering

Then /aae:aae plus the task. Codex users install it with a script and call $aae. Any other agent can follow the plain-text program, AAE.md, in the repository.

Algorithm engineering is a research discipline built on a loop: design, analysis, implementation, experiment. AAE hands the loop to an agent and adds hard rules:

  • Before starting, the person and the agent agree on four things: the benchmark command, the metric, correctness assertions that must hold after every change, and a budget.
  • Before each change, the agent writes a falsifiable hypothesis and predicts the direction and size of the effect.
  • Each change is a git commit. It stays only if the benchmark improves and the assertions still pass. Otherwise it is reset.
  • Each kept change becomes its own numbered patch. A PDF report gets one page per hypothesis, kept or not.
  • The agent may not touch the benchmark harness, the metric, the input data or the budget, and may not add dependencies.

The last rule is the one I would keep if I kept nothing else. An agent that can edit the benchmark it is scored on has an easier way to raise the score than improving the code.

The bench

We ran the project's own quickstart, billed as ten minutes, in a Linux sandbox with two virtual cores and 7 GB of memory. The target computes shortest paths from four sources on two graphs of 90,000 and 100,000 nodes. Its benchmark script fails the run if the output differs from a stored reference by a single byte.

We did not install the Claude Code plugin. A Claude model followed AAE.md's experiment loop - hypothesis and prediction, commit, benchmark, keep or reset, numbered patch - without the per-experiment report files. The project says any agent can follow AAE.md. Budget: ten experiments including the baseline, three timed runs each.

Change Predicted Measured Verdict
Baseline - 6.62 s -
Stop copying each node's neighbor list -20 to -35% -6.5% kept
Distances in an array, not a tree map -25 to -40% -55% kept
Neighbor lists in arrays, not maps -20 to -40% -67% kept
Binary heap instead of a sorted set -15 to -35% -38% kept
Hand-written number parser -15 to -35% -18% kept
One contiguous edge array -5 to -15% -33% kept
Four searches on parallel threads -20 to -40% -31% kept
32-bit edge weights -3 to -12% +4% discarded
Bucket queue for integer weights -10 to -30% -48% kept

Final: 0.111 seconds median. The baseline re-measured between 6.0 and 6.4 seconds, so call it 55 to 60 times faster on this machine. Applying the eight patches in order to the original commit reproduced the final code, and it passed the byte-for-byte check.

Read the prediction column

The agent called the direction right eight times out of nine. It called the size inside its own range twice.

The first change was predicted to save a quarter of the time. It saved 6.5%. Under AAE that miss is not a shrug: the method says the agent's model of the program is wrong and has to be fixed before the next hypothesis. So the agent logged that the copy was not the hot spot and ran a profiler, which put most of the time inside the search and up to a fifth in reading the graph. Its next two hypotheses went after the tree maps used in both places. Those were the two biggest wins, -55% and -67%.

That is what the method buys. A pile of "made it faster" commits tells a reviewer nothing. A prediction next to a result tells a reviewer how well the agent understood the code before it touched it, and a miss shows where it didn't.

Where the record is thinner than it looks

One change was thrown out on noise. At a fifth of a second to half a second, three runs of the same code spread by roughly 20 to 40%. The 32-bit weights change came in 4% slower on the median, and its own three runs spread 38%. A different draw could have kept it. AAE.md says to summarize multiple measurements with a geometric mean, but it does not say how many repetitions an experiment needs. A one-number benchmark with three runs cannot see small effects. Know which of your own benchmarks are that coarse before you let an agent make keep-or-discard calls on them.

Two kept changes lean on this machine and these inputs. The threads pay off because there are two cores. The bucket queue relies on integer weights and sizes itself by the largest one; the agent checked the input files first, and here the largest weight is 1,000, so the queue is small. On inputs with very large weights it would stay correct but could get slow or run out of memory. The benchmark would never show it, because it only measures the inputs it runs.

What we did not do: build the PDF report (its build script needs per-experiment metadata we did not write), or test the plugin's own session flow. The run took under half an hour of agent time. We did not meter its cost.

The big numbers, and whose they are

The project lists results on established open-source solvers. The largest is VieCut, an exact minimum-cut solver: 8.9 times faster on one thread (25.0 to 2.80 seconds in the release's summary) as a geometric mean over a 53-instance benchmark, with every computed cut unchanged. The release also claims 8.8 times on 32 threads, measured against code that already had the single-thread changes, because the old release ran out of memory on part of the set. The 8.9 shipped as VieCut v2.0 on 17 November, with release notes crediting AAE.

KaHIP's graph partitioner kaffpa got 3.9 times faster in total (2.8 times as a geometric mean over 537 runs) with partition quality unchanged. That session ran 122 experiments on 69 hypotheses and kept 41. Smaller gains are listed for a max-flow solver (3.0 times), two partitioners (1.82 and 1.61 times, the second from a session still running; output identical) and a clustering code (1.24 times).

These are the authors' own numbers on the authors' own software. The paper says its authors engineered VieCut, the release was published by Christian Schulz, one of those authors, and VieCut and KaHIP both live under the same KaHIP GitHub organization. The releases and patches are public, so anyone can check them. The context still belongs next to them.

The paper has a smaller, earlier figure. In September, on code the authors had already tuned extensively by hand, the agent found factors of 1.28 (one thread) and 1.63 (32 threads) on real-world k-cores - the most tightly connected parts of large web and social graphs - and much larger factors on DIMACS benchmark instances. The release's own summary says the 8.9 adds a later round of single-thread changes and is measured on a mix of 33 generated instance families and 20 real-world k-cores. The summary does not say how the gap splits between those two causes, and we did not test it.

Where it does not fit

AAE needs a benchmark that runs in seconds or minutes and a correctness check that can fail. Code without a reference output, anything whose "correct" is a judgment call, gives the agent nothing to keep it honest. And the check is only as wide as the inputs: our bucket queue is fast on these graphs and could be slow or memory-hungry on graphs with much larger weights, which the benchmark never runs.

The quickstart is built to be slow, and its own source says so. A 55-times speedup there says nothing about mature code. The paper's single-thread 1.28 on real-world graphs is the more honest expectation for software someone has already tuned.

The fast route in

  1. Run the quickstart (the project says about 10 minutes; it needs a C++17 compiler, Python 3 and awk) to see the loop and the artifacts.
  2. Pick one hot path that already has a reference output: a report generator, a parser, a pricing calculation with a golden file.
  3. Write the four agreements down before starting: the benchmark command, the metric, the correctness check that fails the run, and a budget of ten or so experiments.
  4. Time each experiment more than three times if the expected effects are small, or the keep-or-discard calls will be coin flips.
  5. Review the patches one at a time, hypothesis first. The predictions that missed are the map of where the agent misread the code.
From thinking to doing.
CTA Image

From founder thinking to company building.

Keeping up with AI is one thing. Putting it to work is another. VarOps helps companies turn the capabilities that matter into real operational advantages, without chasing every new model or tool.

Put AI to Work →

Sources

Add VarOps on Google