r/ClaudeCode • u/SirRobinBlibs • 3d ago
Tips & Workflows Anthropic's Rust migration post has a lesson for porting with Claude Code: the first step only saved 8-10%
Anthropic's write-up on moving the Messages API from Python to Rust (25 Nov) has a detail I think matters more than the 70% CPU number. Their first attempt was the usual advice: rewrite only the hot part (the output parser) in Rust and call it from Python. That saved about 8 to 10% CPU, and every token crossed between Python and Rust three times. The gain only came when the whole request path moved.
I ran rust-anything (open source, by Erkam Yaman) on a small Python sample. It plugs into Claude Code as an MCP server and skill. Its own benchmark docs show the same thing: a small function called per item across the bridge got slower (a Go function ran at 0.04x), while moving the loop into Rust gave 3 to 32x.
What I like for Claude Code use: analyze and profile are plain read-only commands, no tokens. go --agent claude then hands one hot function to Claude, records what the original returns, and only switches it on when every recorded case matches plus clippy, tests and an unsafe check. That's the same "tests aren't enough, record the original's behavior" lesson Anthropic describes (98% of tests passing vs about 25% of real inputs matching).
Caveat: the repo is 12 days old, so I'd start with the read-only reports.
I wrote up where Rust fits in the AI stack vs Python, C++, Go and Mojo, with the numbers: https://medium.com/@r3dtuxedo/rust-wont-train-your-model-it-runs-everything-around-it-944db0f1dc1b
I wrote the article.
•
u/AutoModerator 3d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/Ok_Tea4891 3d ago
The detail that every token crossed the Python/Rust boundary three times is a good reminder that the cost of a port often sits in the seam, not in the hot function. For anyone attempting something similar with Claude Code, recording the original's outputs on real inputs as a replay set, instead of trusting unit tests alone, is what closes the gap between tests passing and behavior actually matching. It is also worth measuring how often the boundary is crossed before deciding which slice to move.
1
u/IndiBestEngineer 3d ago
same lesson from a very different place, a game bot. we deleted thousands of unit tests there, a fix counts as done only when the in-game counter moves. the only new tests allowed are replays: load the state recorded in the bot's log at the moment it went wrong, assert the decision, and the replay has to fail without the fix. it only checks the first changed decision though, everything after that is judged live in the game.