Code Lab
Fast-Anything: How Recorded Python Calls Check a Rust Port
CODE LAB · PROJECT SPOTLIGHT
Fast-Anything Rust and Python · MIT
Profile a hot function and verify its Rust port against recorded calls.
Project preview · EL4CTEO/fast-anything
Moving one slow Python function into Rust only helps if callers keep getting the right answer. Fast-Anything profiles a program, records inputs and outputs for a selected function, and uses those calls to check a candidate port. The maintainers report a 116× whole-program improvement for their Python fuzzy-deduplication example with 700 names. The number belongs to that workload and their test environment.

Check the outcome of each recorded call
The excerpt is from the Python replay runner. It separates cases that should raise an error from cases that should return a value. A returned value must match the reference under the project’s comparison rules. This is the test that catches a port which successfully builds and runs but computes something different.
Run a small comparison before porting anything
Save the pinned runner.py beside the snippet and run it with Python 3. The candidate in this exercise counts UTF-8 bytes. The original counts Python string characters. The third call checks a change in return type.
from runpy import run_path
same = run_path("runner.py")["same"]
text = "café"
print("ASCII length:", same(len("cafe"), len("cafe".encode())))
print("Unicode length:", same(len(text), len(text.encode())))
print("Return type:", same(3, 3.0))Observed output
ASCII length: True Unicode length: False Return type: False
ASCII gives the same count by either method. With café, the four characters occupy five bytes, so the comparison fails. Python normally considers 3 == 3.0 true, but the project’s comparator flags the type change. This ran the upstream comparator directly. No Rust port, agent invocation or performance measurement was part of our run.
Use the replay result to decide what to time
Start with one representative workload and additional cases you can inspect before enabling a port. Then compare wall-clock times for the same complete program. A faster individual call can still leave startup, file reads or repeated runtime crossings as the dominant cost. Recordings can include real call arguments. Use a disposable sample dataset when trying the workflow with a coding agent.
Mindung’s introduction · Another example of testing a small part of a larger program
Source excerpt © 2026 EL4CTEO. MIT license.
