How to Port Slow Python Functions to Rust With fast-anything and Claude Code

Published on by

fast-anything is an open source tool that speeds up a program by moving only its slowest functions to Rust. It profiles the program, ranks each function by its share of the run time, records real calls to the top one, and has a coding agent such as Claude Code write the Rust version. Then it replays the recorded calls against that Rust version and switches it on only if every answer matches. The original function stays in the file as a fallback.

We pointed it at a small Python program of our own: a Mandelbrot zoom drawn in the terminal, 168 lines of plain Python that ran at 1.2 frames a second. Two rounds with Claude Code took about six minutes of agent time. At the end, fast-anything’s benchmark measured the program at 46 times faster, and the zoom on screen ran at 33.7 frames a second, about 27 times faster than the original. This guide has every command we typed, what each step printed, and where the speedup stopped.

EL4CTEO on GitHub started and maintains the tool, other developers have sent code to it, and it is licensed under MIT or Apache-2.0, at your option. Python is our test case here, but the README also lists Node.js and TypeScript, Ruby, Java, Kotlin, Go, PHP, C and C++, C#, R, and PowerShell.

What You Need

Our runs used fast-anything 0.9.2, Claude Code 2.1.332, Rust 1.100.1, and Python 3.14 on a four-core Intel N100 mini PC running Omarchy, a desktop setup built on Arch Linux. Since then fast-anything has reached 1.5.1. Its changelog calls 1.0.0 the first stable release and says the commands, flags, and output became the stable interface there, so the commands below still apply. Newer versions may print slightly different tables.

Scanning a program needs only its own runtime, which is Python here. Porting needs the Rust toolchain, which you install with rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

You also need Claude Code, installed and signed in. If you are new to it, our Claude Code guide on Omarchy covers the first session. fast-anything ports top-level functions that take plain data (numbers, strings, lists, maps) and give the same answer for the same input. A function that reads files, writes to the terminal, or uses random numbers stays in Python, and the scan says why.

Install fast-anything and the Claude Code Plugin

The README gives two install routes for the command-line tool:

npm i -g @el4cteo/fast-anything
# or
cargo install fast-anything

When we recorded, npm still served version 0.9.0, so we used cargo and pinned the version with cargo install fast-anything --version 0.9.2 --locked. Both registries now carry 1.5.1, so either route gives you the current release. Check what is installed with:

fast-anything doctor

The plugin adds a slash command to Claude Code. Inside a Claude Code session, add the maker’s marketplace and install the plugin from it:

/plugin marketplace add EL4CTEO/fast-anything
/plugin install fast-anything@fast-anything

The command the plugin adds is /fast-anything:fast. Type the full name. In our version of Claude Code, /fast on its own is a built-in command that toggles fast mode, and pressing Enter on it does that instead of starting a port.

Scan the Program First

Before Claude Code writes any Rust, run the scan yourself. It runs your program under a profiler and prints a table, and it costs no agent time. Pass the command you normally use to start the program after --:

fast-anything scan -- python zoom.py

Our program ran in 6.86 seconds under the profiler. The table ranked fractal.render_frame, the function that computes the escape counts for every pixel, at 94.6 percent of the run and marked it “port it”. fractal.shade, which turns those counts into palette colors, took 1.7 percent and got “too small to matter”. The plugin’s instructions tell the agent to skip anything under 2 percent of the run. Every function in zoom.py that draws or reads the theme file was marked “does I/O”, with the call that blocks it: sys.stdout.write for draw and status, open for theme_colors.

fast-anything scan table for python zoom.py: fractal.render_frame at 94.6 percent marked port it, fractal.shade at 1.7 percent too small to matter, and the zoom.py functions marked does I/O

Run this on your own program first. If no function has a large share, or the top ones all do I/O, a port will not help much, and you learn that before you spend any agent time.

Round One: Port the Hottest Function

Start Claude Code in the project folder and give the plugin command the program’s start command:

/fast-anything:fast python zoom.py

Claude Code ran the scan, then fast-anything port fractal.render_frame. The port step runs the program again, records real calls to the function, and creates a one-function Rust crate under .fast/ with a stub and a TASK.md that tells the agent what to write. Claude Code wrote the Rust, ran cargo check, and then ran verify.

Then fast-anything replayed 81 cases against the Rust version: 48 calls recorded during a real run, 12 more recorded calls that were held back from Claude Code, and 21 edge cases. All 81 gave the same result as the Python function. The held-back calls matter because the agent never saw them, so the Rust cannot be tuned to pass only the inputs it was shown. Per the README, nothing is switched on until every case matches.

The enable step then appended a small switch block to the end of fractal.py. That block loads the Rust version and checks the FAST_ANYTHING_DISABLE variable. The Python function above it stays as it was, and git status shows fractal.py as modified. Claude Code’s own summary said “fractal.py itself is unchanged”, which is wrong: the function bodies are untouched, but the file changed. Read the diff yourself after each round.

Claude Code finished with bench and report. In fast-anything’s benchmark, the median of five rounds, the whole program went from 6.90 seconds to 300 milliseconds, about 23 times faster. Each render_frame call dropped from 110.1 milliseconds to 1.0 millisecond, about 110 times faster. Claude Code’s Rust splits the frame’s rows across the CPU cores, so part of that gain comes from using all four cores of the N100. The README notes that ports use every core, so whole-program speedups grow with the thread count. The round took 2 minutes 52 seconds.

Compare the Two Versions Side by Side

The benchmark runs the program with its output going to a log file instead of a terminal, so it draws a small 120 by 40 frame and nothing reaches the screen. To see the on-screen difference, we started two copies of the zoom side by side. The left one ran with the Rust switched off:

FAST_ANYTHING_DISABLE=1 python zoom.py

The right one ran plain python zoom.py, which now uses the Rust render_frame. Both drew the same picture. The Python side took 48.9 seconds at 1.2 frames a second, and the Rust side took 2.7 seconds at 22.3 frames a second, about 18 times faster.

Two terminal windows showing the same fractal frame after round one: the original Python at 1.2 fps in 48.9 s on the left, the Rust port at 22.3 fps in 2.7 s on the right

The on-screen gain is smaller than the benchmark’s 23 times because each on-screen frame is about six times larger than the benchmark’s, it is still built as text in Python, and the terminal then has to show it.

Round Two: Split the Drawing Code and Port It

A second scan shows where the time went after the first port. We typed this follow-up in the same Claude Code session:

Scan again with the Rust port on. If the drawing is now the slow part, move the pure part of it into its own module so fast-anything can port it, keep the printing in zoom.py, and port it the same way.

fast-anything does not port a function that writes to the terminal, and draw builds a long string of color codes and then prints it. The rescan put draw at 52.5 percent of the run, nearly all of it building that string, and shade at 27.7 percent.

Claude Code moved the string building into a new file, screen.py, with a pure function frame_text(indexes, palette, width, height) that returns the frame instead of printing it. draw in zoom.py now only calls sys.stdout.write(frame_text(...)). Claude Code checked that frame_text gave exactly the same text as the old draw on a few frame sizes, then ported it. It also ported shade, which had grown from 1.7 percent to 27.7 percent of the run. Each port passed all 360 of its checks.

Claude Code's round two summary: python zoom.py is 46x faster end to end, 6.85 s down to 148 ms, with the new scan and the new screen.py module listed

frame_text got 8.1 times faster per call. shade got only 2.0 times faster (363 to 179 microseconds), because most of its time now goes to moving its list of counts into Rust and back. The benchmark put the whole program at 6.85 seconds down to 148 milliseconds, 46 times faster, after a round of 3 minutes 7 seconds. The final scan found no function worth porting: what is left mostly writes to the terminal.

On screen, the Rust side now finished the zoom in 1.8 seconds at 33.7 frames a second, about 27 times faster than the original Python.

The same fractal frame side by side after round two: the original Python at 1.2 fps in 48.9 s, the Rust port at 33.7 fps in 1.8 s

The remaining limit is the terminal write. Each frame sends a 24-bit color code pair for every character cell, and fast-anything leaves that I/O in Python by design.

Switch a Port Off

To run the original Python once, without any port, set the variable we used on the left-hand window:

FAST_ANYTHING_DISABLE=1 python zoom.py

To remove one port for good, run disable with the function’s id. That removes the function’s switch block from the file:

fast-anything disable fractal.render_frame

fast-anything status shows which ports are on. fast-anything report writes a Markdown report and an SVG card, which is handy for a pull request description.

Troubleshooting

/fast toggled fast mode instead of porting. Type the full /fast-anything:fast name with the program’s command after it. If you leave out the command, the plugin tries to work out how the program runs from the README or the project files.

The function you want is marked “does I/O”. Split it the way round two did. Move the pure part, the code that computes a value from plain inputs, into its own module and keep the reading or printing in the original function. Then scan again. fast-anything’s own skill file suggests the same move when a function’s I/O is the blocker.

The benchmark and the screen disagree. They measure different things. bench runs the whole program with its output going to a log file, at a small 120 by 40 frame, and reports the median of five rounds, so it leaves out most of the drawing cost the screen still pays. In round one we saw 23 times in the benchmark and 18 times on screen.

A small function barely speeds up. Every call crosses from Python into Rust and back, and the data is converted each way. For a cheap function like shade, that crossing costs about as much as the work. The README says fast-anything ports the outermost loop it can so the program crosses into Rust once instead of millions of times, and a port that is slower per call stays off.

Start With a Scan

Start with fast-anything scan on the command you already use to run your program. It uses no agent time and tells you whether one or two functions hold most of the time. If they do, the plugin gets you a checked Rust port in a few minutes, and a follow-up request can split I/O out of the next slowest function. The checks compare answers, not code, so read the Rust Claude Code writes before you commit it, and read the diff of the original files too.

For more on running coding agents on Linux, see our guides to Codex on Omarchy and running several coding agents side by side with Herdr.