跳到正文
DEV Community· David Díaz·· 2 小時前AI 評分60

fast-anything 以熱點函數為目標,提供選擇性 Rust 移植流程

fast-anything targets hot functions instead of Rust rewrites

AI 導讀

開源專案 fast-anything 會剖析應用程式以找出熱點函數,生成單一函數的 Rust 移植任務,並只在驗證通過後替換原函數。驗證會重播記錄的呼叫、生成邊界及縮減案例;若行為檢查失敗或移植版本每次呼叫較慢,便不會啟用。專案報告的端到端示例介乎 2.7× 至 116×,但並非獨立基準;工具只針對接受純資料的頂層確定性函數。

正文

The open-source fast-anything project packages a selective alternative to rewriting an application in Rust: it profiles a program, identifies hot functions, generates a one-function Rust porting task, and can replace the original only after verification. For developers, the consequence is a workflow aimed at narrowing native-code work to a measured bottleneck rather than treating a language rewrite as the default performance project.

A profiling-first porting loop

The tool’s scan command profiles a supplied application and ranks functions using execution time and portability; port records up to 500 calls and creates a Rust crate plus TASK.md; verify builds the port and replays the captured calls. Its documented command supports Python, Node, Bun, Deno, Ruby, Java, Go, PHP, C/C++, C#, and R entry points, while the project lists language-specific support requirements and bindings. fast-anything README

The project also frames coding agents as implementers rather than arbiters. Its --agent option accepts Claude, Codex, or another command that reads a prompt from standard input, but the resulting port must still pass the tool’s checks before it can be enabled. fast-anything README

Those checks go beyond a small hand-written test set. According to the repository, verification compares recorded calls with the original function, generates edge and shrunk cases, checks errors where the original errors, and treats negative zero distinctly from zero. Every fifth recorded call, beginning with five calls, is held out from the agent’s working crate and replayed during verification. fast-anything README

Native code remains optional

enable and disable swap the Rust implementation in or out, and FAST_ANYTHING_DISABLE=1 forces execution through the original implementation. The project says it will not enable a port that fails behavioral checks or is slower per call than the source function, including cases where the boundary-crossing cost exceeds the saved computation. fast-anything README

The repository reports example end-to-end results ranging from 2.7× for C++ fuzzy deduplication to 116× for a Python fuzzy-deduplication example, with runs described as using an i5-10500 on Windows 11 except for C and C++ examples run on a four-core GitHub Actions Linux runner. These are project-reported examples, not an independent benchmark, and the repository points readers to its examples/ directory for reproduction. fast-anything README

The constraint is also the point

The approach is deliberately limited to top-level deterministic functions that accept plain data; the project documents exclusions and explains why a candidate cannot be moved. It also says it seeks to port the outermost practical loop, reducing repeated crossings into Rust rather than accelerating only an inner helper. fast-anything README

Analysis: That restriction is the project’s most credible design decision. A native replacement that cannot be isolated, replayed, and disabled creates a larger maintenance and debugging surface than the performance fix may justify. The unresolved trade-off is coverage: stateful, object-heavy, callback-driven, or otherwise non-portable bottlenecks may be precisely the functions a team most wants to improve, yet they fall outside the workflow’s stated target. fast-anything README

來源:DEV Community · dev.to