Rust Anything: Verifying AI-Assisted Rewrites Beyond the 19× Claim
An AI agent can turn a small JavaScript module into compiling Rust quickly. The difficult question is whether the new implementation preserves everything callers depend on: Unicode indexing, errors, special numeric values, ordering, and the side effects that a test suite may never exercise.
Rust Anything builds a migration workflow around that question. The agent writes the replacement, while the tool records the original's behavior and compares the port against it. Its main contribution is a feedback loop for checking a rewrite, rather than an automatic translator that makes every program faster.
The project's Prettier example advertises a roughly 19-fold command-line improvement. A warmed in-process comparison produces a much smaller result. Both can be correct because they measure different execution paths. Understanding the boundary of each benchmark is as important as understanding the port itself.
Compilation is only the first compatibility check
A successful Rust build establishes that the code satisfies the compiler's rules. It does not establish that the port implements the original API's semantics.
Two functions can accept the same apparent inputs and return different results for an emoji, negative zero, or an empty collection. They can also agree on ordinary inputs while differing in error behavior or the order of equally ranked results.
Those differences can be expensive because callers may rely on behavior that was never documented as a formal contract. A fuzzy-search score, for example, can influence which result a user sees first. A small numeric mismatch can therefore become an interface change.
Rust Anything keeps the original implementation available as a reference. That provides a concrete oracle for selected inputs, while avoiding the assumption that rewriting in a safer systems language automatically preserves the old program's meaning.
A bridge preserves the calling boundary
Incremental migration needs a way for existing callers to reach a replacement implementation. A bridge wraps the Rust code in an interface that the original runtime can call.
This allows a team to replace a unit without rewriting every caller at once. It also creates a performance boundary: values need to move between runtimes, and some representations need conversion.
The best migration target is therefore not simply the shortest function that looks inefficient. It is a unit whose useful computation is large enough to justify the call and conversion overhead, and whose interface can be represented accurately across the bridge.
The tool integrates with coding agents through MCP and related setup. That makes the verification commands available during development. It does not remove the need to understand which runtime owns the entry point, where errors cross the boundary, and which implementation currently handles a call.
Recording turns the original into an executable reference
A behavior record captures what the original does for generated or supplied inputs. The port can then be run against the same cases.
The important property is repeatability. Instead of asking an agent whether the new function looks equivalent, the workflow asks it to reproduce observable outputs under defined conditions.
Generated cases can target language boundaries that ordinary examples miss: empty strings, long strings, unusual Unicode, missing fields, and values near numeric limits. Existing tests and real inputs can supply a different set of cases, especially when the application's behavior depends on a particular data distribution.
Recording has limits. A finite corpus is not a proof over every possible input. Nondeterminism can also make a correct implementation appear different unless the experiment controls time, randomness, or external state.
It is also real execution. Running an original server or command can modify files, contact services, or update data. A migration evaluation needs a controlled environment and representative test data, not an accidental replay against production dependencies.
A Unicode mismatch shows what differential testing catches
JavaScript and Rust do not expose strings through the same indexing model. JavaScript APIs commonly express positions in UTF-16 code units. Rust strings are UTF-8, and operations may expose byte offsets or iterate over Unicode scalar values.
A replacement that counts characters where the original counts UTF-16 units can look sensible and still be incompatible. An emoji outside the Basic Multilingual Plane commonly occupies two UTF-16 code units, so later positions shift relative to a one-scalar count.
The lesson is not to replace every Rust string operation mechanically. It is to identify which original semantics the API promises to callers. A port may need explicit UTF-16 accounting at that boundary even if native Rust indexing would be more idiomatic elsewhere.
Differential testing is especially useful here because it produces an actionable counterexample. The agent receives an input and two outputs, then narrows the cause. That is more concrete than a general review comment about possible Unicode problems.
The same reasoning applies to numeric conversions. A port must decide how the original represents non-finite values, integer overflow, and distinctions such as negative zero. The right answer depends on the API being preserved.
Profiling should determine what moves first
A migration workflow is more useful when it begins with measured cost. Profiling identifies where execution time is spent, while analysis helps organize candidate units and their dependencies.
A slow end-to-end operation can be dominated by startup, disk access, network latency, or repeated serialization. Rewriting an internal computation may leave the dominant cost untouched.
This is why a candidate should have both a correctness target and a performance target. The correctness target describes the behavior to preserve. The performance target describes the workload and boundary where improvement matters.
For a formatter, that might mean processing a repository in one long-lived process. For a small command-line tool, process startup may be part of the real user experience. Neither target is inherently superior; they answer different questions.
A small port is also easier to compare, review, and revert. The unit boundary becomes a practical control over the migration's risk rather than merely a convenience for the coding agent.
Gates combine several kinds of evidence
Behavior matching is one part of a release decision. Formatting, linting, tests, unsafe code review, and checks for incomplete implementations address other failure modes.
A passing gate should be read as evidence under its stated checks. It does not prove that the implementation is free of all bugs, that every input is covered, or that a runtime bridge preserves every possible object shape.
The current project documentation is explicit about a boundary in recorded behavior: error types are compared, while error message text is not necessarily part of the comparison. If callers depend on exact messages, the application needs additional assertions for that contract.
That example shows why the checks themselves deserve review. A green result is only as broad as the observations and acceptance rules behind it. Understanding what is ignored can be more valuable than adding another large number to a pass count.
A partial port can keep a fallback
A complete application can migrate incrementally through a front door that routes covered units to Rust and leaves remaining behavior with the original implementation.
Fallback makes it possible to deploy a useful subset before every parser, route, or plugin is ported. It also complicates claims about completeness. Byte-identical output from the combined system does not mean every result came from Rust.
A useful report separates coverage from compatibility. Compatibility asks whether the whole system returns the accepted result. Coverage asks how much of the workload the new implementation actually handles. Performance depends on both, as well as the overhead of the routing layer.
The fallback path needs testing too. A migration can fail at the boundary between implementations, even if each side works correctly in isolation. Inputs must not disappear, and an unsupported case should not silently acquire a different behavior.
The Prettier headline includes process startup
The project's real-world benchmark report includes a command-line comparison that starts a process per file. On the reported Apple M4 setup, roughly 2,360 covered JavaScript and TypeScript files took about 128.6 seconds with Prettier and 6.9 seconds with the Rust path.
That is close to the advertised 19-fold ratio. It includes the cost of repeatedly starting the original runtime, so it describes the whole command-line arrangement rather than only the formatting algorithm.
The same report gives an in-process warmed comparison of approximately 600 milliseconds against 143 milliseconds for the stated workload, about 4.2 times faster. The smaller ratio does not contradict the first result. Removing repeated startup changes which costs dominate.
| Benchmark boundary | What it includes | How to interpret it |
|---|---|---|
| New process for each file | Startup plus formatting and surrounding work | Relevant to repeated cold CLI invocation |
| Warmed in-process calls | Formatting inside an already running process | Closer to an editor or persistent worker |
| One component through a bridge | Conversion plus that component's work | Tests whether the chosen boundary is efficient |
These are author-reported results on a specified machine and version. They are not independent measurements made for this article, and they should not be generalized to every repository or supported syntax.
Crossing the bridge can reverse the result
A small function can be slower in Rust when most of its cost lies in converting and transporting arguments. The Prettier report includes a document-printer component called from JavaScript through a bridge that performs worse than the JavaScript version.
The mechanism is straightforward. Moving a structured document into another runtime can require a large conversion before the supposedly faster computation begins. Returning the result adds another conversion. If the computation itself is short, those costs dominate.
Batching more work across the boundary can improve that balance. A complete formatting operation has a different cost structure from thousands of tiny printer calls. That is an architectural decision, not an optimization that follows automatically from choosing Rust.
The useful benchmark therefore resembles the intended integration. A microbenchmark with native inputs can hide the conversion costs that production pays on every call. Conversely, a cold CLI benchmark can overstate the gain for a process that stays alive all day.
Compatibility becomes an ongoing maintenance responsibility
A port tied to one upstream version has a moving target. New syntax, configuration options, bug fixes, and plugin behavior can change the reference implementation after the first migration passes.
A team maintaining the port needs a policy for upstream updates. Keeping a corpus of representative inputs helps detect behavior changes, but the corpus must evolve with the product. Fallback coverage should also remain visible instead of becoming an undocumented permanent dependency.
Performance maintenance matters too. A new bridge layer, changed argument representation, or upstream optimization can alter the comparison. The benchmark that justified the migration should remain reproducible as both sides change.
For a team that only needs a faster formatter, an established formatter may be a simpler choice. Rust Anything is more interesting when the application has valuable existing behavior that must be preserved while a measured bottleneck moves into another runtime.
Final thoughts
Rust Anything makes compatibility checks part of the agent's development loop. Recording, comparing, benchmarking, and gating create more useful feedback than accepting a port because it compiles or looks idiomatic.
The checks still have boundaries: finite inputs, explicit comparison rules, fallback coverage, and the cost of crossing runtimes. The 19-fold Prettier result is best understood as one workload measurement. A sound migration decision combines preserved behavior with a benchmark that matches how the replacement will actually run.