fast-anything Finds Your Slowest Function, Then Tells You to Ignore It

A Rust CLI that profiles Python, Node, Ruby, and eight other languages, hands the hot 5% to a coding agent, and gates every port behind replayed real calls. Its sharpest idea is about the cost of crossing a language boundary.

9 min read • View on GitHub • More from EL4CTEO

A black ink editorial illustration of a customs checkpoint between two territories. On the left, a long single-file queue of thousands of identical tiny parcels waits at one narrow inspection gate, the line receding past the frame edge. On the right, a single large container truck rolls through a wide lane carrying the same parcels inside it. A customs officer stands between the lanes, one hand raised to halt the parcel queue and the other waving the truck through. The scene illustrates the fixed cost of crossing a language boundary once versus paying it millions of times.
Every call from Python into Rust pays a fixed toll. One truck through the gate beats a million parcels, which is exactly the move fast-anything nudges you toward.

Don't rewrite it in Rust. Rewrite the 5% that's slow.

EL4CTEO, Creator · EL4CTEO/fast-anything
Key Takeaways

A 35× Function That Made the App 1.9× Faster

A ported function that runs 35 times faster sounds like a clear win. In fast-anything's own benchmark for a Python fuzzy-deduplication app, porting the Levenshtein distance function to Rust delivered exactly that: 35× on the function. The application got 1.9× faster.

Both numbers come from the same run. That gap between them is the most interesting thing in the repository, and almost nobody who shares the project online mentions it. They share the star count instead.

The cause is the language boundary. Every call from Python into Rust pays a fixed toll: argument marshaling, the FFI hop, the return trip. A function called a few million times pays that toll a few million times. The Rust arithmetic is nearly free. The crossing is not.

fast-anything could have stopped there and shipped a porting tool. Instead it built a rule that stops you from making this mistake in the first place.

A caveat worth stating up front: these figures are project-authored example runs, not independently reproduced benchmarks. Treat them as a demonstration of a mechanism, not a guarantee about your codebase.

The Rule That Says "Port the Caller"

Before fast-anything recommends anything, it ranks every function in the profile by a single number. That number is the product of two factors: how much of the runtime the function accounts for, and how portable it is.

pub const WORTH_IT: f64 = 0.02;

h.share = (h.cumtime / wall).clamp(0.0, 1.0);
h.portability = if h.portable() { h.portability.clamp(0.0, 1.0) } else { 0.0 };
h.score = h.share * h.portability;

The share uses cumulative time, so an outer function's share includes the work of everything it calls. Portability is a score between 0 and 1, and it is forced to 0 for any function with blockers. Nothing below a 2% share of runtime clears the WORTH_IT floor.

Then the ranking does something unexpected. For each portable function, it looks for a portable caller in the same file whose share is at least 90% of the callee's share. If one exists, the callee is marked as covered and its score is set to zero.

// a portable caller in the same file that carries the work
*share >= 0.9 * h.share

This is the outer-loop rule, and it is the reason porting the caller beat porting the callee in that benchmark. One crossing for the whole loop replaces millions of small crossings. The tool does not just find your slowest function. It finds your slowest function and then tells you to port the one above it.

The ranking engine in one screen. Drag the process share slider across 0.9 and watch the inner function's score collapse to zero, because a portable caller now covers it.

A black ink editorial illustration showing a close-up of a hand holding a magnifying glass over a hand-written numbered ranking list on a sheet of paper that fills the frame. Line number one is crossed out with a heavy stroke, and a curved arrow leads from it down to line number two, which is circled. The magnifying glass hovers over the crossed-out line, and inside the lens the faint word covered appears enlarged beside it. The image visualizes fast-anything demoting the top-ranked function in favor of the portable caller that wraps it.
The tool's most counterintuitive move, drawn as a decision: the top-ranked item gets crossed out because something above it already carries the work.

The behavior is pinned by two unit tests. outer_loop_covers_inner_function checks that a portable caller demotes its callee. portable_beats_bigger_but_blocked checks that a blocked main holding 100% of runtime ranks below a portable lev holding 90%. The second test is the whole philosophy in one assertion: coverage matters more than raw share, and portability is a hard gate.

Be honest about the 0.9 threshold, though. It is a tuned heuristic, not a derived constant. A caller that spends 91% of its time in the callee and 9% elsewhere is treated as the cover. That is a reasonable call, but the test suite does not sweep the threshold to show that 0.9 is optimal.

Why Anyone Builds This

Now that the mechanism is on the table, the origin makes more sense. The pitch is not "rewrite your service in Rust." It is "rewrite the 5% that is slow."

A full rewrite is a non-starter for most teams. It takes months, it touches everything, it is nearly impossible to review, and it is irreversible once it lands in production. A narrow port of one function, wrapped in a marked block you can strip out byte for byte, is something a team will actually approve. The intended user is a developer who already has a coding agent in their workflow and wants a measurable, undoable change in one specific place.

A WSJ hedcut-style editorial portrait of EL4CTEO, the creator of fast-anything, rendered in black ink on a pure white background.

The tool ships as a Rust CLI, published on both npm and crates.io under the MIT license. It supports eleven languages: Python, JavaScript and TypeScript, Ruby, Java, Kotlin, Go, PHP, C, C++, C#, and R. Python and Node get native bindings through PyO3 and napi-rs. The other languages converge on a shared C ABI with JSON passed across the boundary. There is also a Claude Code plugin, an MCP server exposing eight tools, and a skill file, so an agent can drive the whole loop.

Scan, Port, Verify, Enable, Bench

The pipeline runs in five stages, with a report at the end. Each stage is a function that opens the project, does its work, and persists the result to a state file that every later command reads.

  1. scan profiles the app and ranks functions by share times portability. It detects the real interpreter, unwrapping environment runners like uv run or poetry run so the profiler hooks the actual process.
  2. port re-runs the app, records up to 500 real calls to the chosen function, and generates a one-function Rust crate plus a task brief for the agent.
  3. verify builds the crate in release mode and replays every recorded call, plus derived and edge cases, against the original's answers.
  4. enable / disable inserts or removes the Rust call site inside a marked block.
  5. bench times the whole app, original versus Rust, in interleaved runs.
  6. report produces markdown and an SVG card ready for a pull request.

Two details show unusual care. The first is a hidden __replay subcommand. Verification runs in a child process, and the comment in the source says why: "so a crashing port can't take it down." A Rust port that segfaults gets caught as a failed case instead of killing the tool.

The second is staleness. At port time, fast-anything snapshots the exact source lines of the original function. Later, when you ask it to enable or bench, it checks that those lines still exist in the file. If you have edited the function since the port was recorded, the tool knows the recorded calls and the Rust port may no longer match, and it can say so. It is text matching rather than AST hashing, which is less robust but works across all eleven languages without writing a parser for each one.

The Gates

Four constraints define the shape of the tool. They are also the fastest way to tell whether your own codebase is a candidate.

The portability gate. Any function with blockers gets its portability forced to zero and drops out of contention. Blockers are the things a Rust port cannot faithfully reproduce: unsupported types, mutating calls, and the like.

The mutation gate. If the recorded calls show the function mutating its arguments, porting bails with an instructive message rather than a stack trace.

A Rust port can only return a value, so it would drop those changes.
Have the function return the new value instead, then scan again.

That is a semantic constraint enforced at recording time, not at compile time, and the error tells you exactly how to restructure the function so the tool can help you.

The plain-data gate. If no calls were usable, the error lists the unsupported types it saw and the ones it supports: numbers, strings, bytes, lists, tuples, dicts, sets. Anything richer than that needs a different approach.

The staleness gate. As described above, a port whose source has drifted since recording is flagged rather than silently enabled.

What It Is Not

fast-anything does not invent a new compiler, profiler, or binding technology. Every piece it uses already exists. Its contribution is the workflow that composes them, so read the table below as a map of layers rather than a scoreboard.

ToolWhat it isFinds hotspotsGenerates the portVerifies behaviorReversibleMulti-language
fast-anythingProfile, port, verify, toggle workflowYesYes, via agentYes, replayed callsYesYes, 11 languages
py-spySampling profiler for PythonYesNoNoNoNo
ScalenePython CPU and memory profilerYesNoNoNoNo
cProfilePython standard profilerYesNoNoNoNo
CythonCompiles Python to C extensionsNoPartial, hand-writtenNoPartialNo
NumbaJIT for numerical PythonNoNoNoNoNo
PyO3 + maturinRust and Python binding toolkitNoNoNoNoNo
Full rewriteReimplement the whole appNoNoNoNoNo

Profilers diagnose. Compilers and JITs accelerate within one ecosystem. FFI frameworks help you write bindings by hand. fast-anything is the only row that runs the whole loop and hands you a one-command undo. That is a composition, not a breakthrough, and it is worth saying plainly.

Rust, or Hindsight?

The most substantive pushback came from a Hacker News thread, and it deserves a fair hearing. The argument: algorithm and data-structure choices, plus the hindsight of rewriting anything with performance in mind, may explain as much of the speedup as the language does.

I would like to argue that one could make most codebases 50% faster if rewritten from scratch with performance in mind even in the same language.

zodwick, Hacker News commenter · HN discussion

The counter to that counter is also on the thread, and it is measured rather than dismissive.

I mean, it's definitely both. Of course there can be algorithmic improvements, but a like-for-like rewrite of Python code into Rust can often be 10x faster.

Hacker News commenter, Hacker News commenter · HN discussion

Here is the honest part: fast-anything's own design partly concedes the point. Choosing the outer loop over the inner function is a structural decision, not a language decision. The tool is telling you to change where the work happens, and Rust is just the vehicle. Whether the 35× came from the language or from the restructuring is not something the project's example runs can settle.

That is the open question worth carrying away. If the speedup is mostly hindsight, then any disciplined rewrite would capture it, and the language is a detail. If it is mostly the boundary, then the outer-loop rule is the real product and everything else is packaging. fast-anything is a bet that it is both, and it gives you a way to find out on your own code without committing to anything you cannot undo.