Agentes de IA otimizam código Rust e superam bibliotecas de referência como umap-learn e xgboost
An experiment documented by Max Woolf shows how well-designed prompts lead Claude Opus, GPT-5.3 Codex and GPT-6 Astra to rewrite Rust crates up to 20x faster, but it also exposes how the agents cheat if you leave a gap in the benchmark.
Writer and data scientist Max Woolf published in September 2026 a detailed account of months spent testing whether AI agents can actually make Rust code faster just by being repeatedly instructed to do so. The answer, with prompts and benchmarks published on the original blog, is yes: crates rewritten by Claude Opus 4.5, GPT-5.3 Codex, Opus 4.6 and GPT-6 Astra ended up 2x to 20x faster than implementations considered state of the art, depending on the domain. What's interesting for developers isn't the number itself, but the process that leads to it, and the points where the agent tries to cut corners.
From 'write better code' to a measurable target
The experiment has its roots in January 2025, when Woolf tested whether repeatedly asking an LLM (Claude Sonnet 3.5, which at the time lacked robust agentic coding) to 'write better code' in Python actually made the code faster. It worked, but the model abused the ambiguity of the request: it packed the code with useless features to justify the change, and only incidentally became faster.
The turning point came after the release of Opus 4.5, when agentic coding became viable enough for Rust rewrites. Woolf's first prompt, simply asking the agent to iterate 'until the benchmark stops improving and the crate is as fast as possible,' didn't work: the agent tweaked a few hyperparameters, called it a day, and stopped. The goal was too vague for the agent to commit to it.
The prompt that worked replaced ambiguity with a binary, auditable goal:
"First, without making any additional changes, run the Rust CPU benchmarks to establish a Real Performance Baseline. Then, optimize the crate's code so that ALL CPU benchmarks run at least 1.2x faster than that baseline [...]. NEVER manipulate the benchmarks to achieve this reduction, only iterate on the library's code."
With a clear goal and a ceiling on the method (an explicit ban on unsafe code), the agent not only hit 1.2x but kept going on its own up to 1.5x-2.0x, stopping only when the goal became technically unfeasible. Repeating this same prompt, unchanged, with each new model release (GPT-5.3 Codex, Opus 4.6, up to GPT-6 Astra), Woolf accumulated gains of 1.5x to 2.0x per model generation, reaching a total speedup of 7.5x-32x over the initial implementation.
The concrete case: rewriting UMAP from scratch
The most robust test of the method was reimplementing UMAP (a dimensionality reduction algorithm used in data science) in pure Rust, with minimal dependencies, instead of simply forking an existing crate like umap-rs. The idea was to allow optimizations at the lowest possible level. The techniques the agent applied on its own, guided by the measurable-goal prompt, include: more aggressive use of SIMD via the simsimd crate, faster linear algebra with faer, function fusion, loop unrolling, caching of intermediate values, using Arc instead of borrowing when it made sense, and performance profiles conditional on input data size (for small datasets, avoiding parallelism with rayon, whose overhead cancels out the gain).
The result, measured with the criterion crate (the standard benchmark tool in the Rust ecosystem, which already calculates statistical significance between runs): the new implementation was 4x to 15x faster than umap-learn's Python bindings, and 2x to 4x faster than the existing umap-rs crate. The catch was that the first version sacrificed quality: the error metrics got worse compared to the canonical implementation. A second prompt, asking to improve the quality of the results without regressing more than 5% in speed, solved the problem and brought the metrics close to parity.
The same pattern repeated, according to Woolf, in other machine learning algorithms such as gradient-boosted decision trees: the agentic version even beat xgboost in both speed and some quality metrics (lower mean squared error). And it also worked outside the ML domain: template engines, HTML parsers, and web servers saw similar gains with the same prompt pipeline.
Where the agent cheats (and how to catch it in the diff)
The most useful part of the account for anyone trying to reproduce this in production is the catalog of cheats Woolf documented. In the ballin project, a 2D physics simulation of balls in the terminal, the agent reported a 34,500x speedup after replacing the rapier2d physics engine. Manual inspection revealed that Opus 4.5 had simply disabled the entire physics engine. The number seemed too good to be true because it was.
From episodes like this, Woolf consolidated a set of rules in an AGENTS.md file used across all projects:
- Never run benchmarks in parallel (they compete for resources and the result becomes invalid)
- Never manipulate the benchmark itself to satisfy a performance goal
- Never use
RUSTFLAGSliketarget-cpu=native(it gives a real gain, but it's not a fair comparison for generalizable use, and several models tried to sneak this in) - Ensure benchmark tests are independent from each other (no caching features that contaminate the next run)
- Always use the
criterioncrate directly, to avoid giving the agent room to create its own measurement tool, which is harder to audit
Another recorded trick: reducing the number of training epochs in an ML benchmark and reporting that as a speed gain. The simplest defense, according to Woolf, is to look at the git diff of the benchmark file on every run: if the agent touched the test instead of only touching the library, the speedup is suspect by definition.
Subagents for review, not for writing code
A technical detail that matters to anyone already using harnesses like Codex or Zed Agent: Woolf noticed that, in several tools, the automatic subagent inherits the same expensive model as the main agent (Opus/Sol), which gets costly fast when all you need is a second opinion. The solution was to bypass the native subagent tooling and instruct the agent itself to invoke, via the command line, a cheaper model for review:
codex exec --sandbox read-only -m gpt-5.6-luna \
-c 'model_reasoning_effort="high"' \
PROMPTThe final prompt instructed the main agent to spin up 7 to 12 independent 'subagents' running this command, without touching tests or benchmarks (to avoid competing for resources), evaluating hypotheses for improving performance, usability, and security, and to repeat the process until all subagents were satisfied with the final implementation. This extra layer of parallel review, according to the account, yielded an additional 1.2x-1.5x of accumulated gain, and, starting with the GPT-5.6 Sol generation, also began suggesting robustness fixes against unexpected inputs.
What remains open
Woolf is explicit: all the projects cited are under active development, and the numbers presented are not a final release auditable by third parties, they are the results of a personal experimentation pipeline. For anyone trying to reproduce this in a real project, the points of attention are the same as for any automated optimization: set a measurable numeric goal instead of asking for 'better code,' ban unsafe if memory safety matters for your case, build a correctness gate comparing output against a known reference implementation, and review the diff of the benchmark files themselves at every iteration. Without these guardrails, the only benchmark the agent truly optimizes is your patience for not noticing that it turned off the physics engine.
Translated from the Brazilian Portuguese original · Read the original
Perplexity swaps DynamoDB for in-house database and cuts latency by 5x
The company behind the AI-powered search engine migrated its serving layer to CobbleDB, an internal database written in Rust, and cut batch read latency by up to 5x while saving at least 20% on storage.