AIsaAIsaStudio English 打开 AIsa Studio

EL4CTEO 开源 fast-anything:用编码智能体只把应用最慢的 5% 移植到 Rust

原标题:EL4CTEO/fast-anything: Don't rewrite it in Rust. Rewrite the 5% that's slow: profile Python, Node or Ruby apps, port the hot functions with your coding agent, prove they behave the same.

EL4CTEO 开源了 fast-anything,对 Python、Node、Ruby 等应用进行性能剖析,让编码智能体只把慢函数移植到 Rust,并用真实记录的调用和派生的边界用例验证移植后行为一致再启用。README 实测示例中 Python 模糊去重提速 116×、TypeScript 提速 20×;支持 Claude Code 插件、MCP server 和 Skill,MIT 许可,创建 1 天已获约 1259 星。

为什么值得看

工具用真实调用记录验证 Rust 移植的正确性和收益,避免整体重写,读者可评估是否引入自己的性能优化流程。

阅读原文 ↗11月23日 AI 日报

本页的摘要、推荐理由与解读出自 AIsa Studio 的 AI 风向智能体,原文版权归原作者所有。

深度解读

发生了什么

GitHub 上出现了一个新仓库 EL4CTEO/fast-anything,创建仅 1 天就获得了 1259 星(平均每天 1193 星),成为 GitHub 上的爆发项目。

项目的标语直接点明主张:「Don't rewrite it in Rust. Rewrite the 5% that's slow.」(不要用 Rust 重写整个应用,只重写最慢的 5%。)标题针对 Python、Node、Ruby 应用,其工具链和文档还覆盖 TypeScript、Java、Go、PHP、C、C++、C# 等。

关键细节

fast-anything 自动化的完整流程:

  • 剖析:scan 对运行中的应用做 profiling,按「耗时 × 可移植性」对函数排序。
  • 录制:port 录制目标函数最多 500 次真实调用,创建一个单函数 Rust crate 以及给智能体的 TASK.md。
  • 验证:verify 以 release 模式编译移植代码,并把每一次录制调用与原函数回放比对。
  • 切换:enable / disable 接入或移除 Rust 代码——原代码保留在「一个标记块中,逐字节移除」,且 FAST_ANYTHING_DISABLE=1 随时可回退到原实现。
  • 基准与报告:bench 交错计时对比原版与 Rust 版;report 生成 markdown 和 SVG 卡片供 PR 使用。

验证不止于回放录制调用。README 的「Proof, not vibes」部分展示了一个错误移植——「比较字节而非字符」——被「500 次真实调用中的 148 次」捕获。除录制调用外,工具还会推导边界用例(NaN、±infinity、-0.0、0、±1、非 ASCII 文本、空输入和最大 16 倍的输入)以及缩小输入。规则是:「Nothing is enabled until every case matches: same values (floats within 1e-9), errors where the original errors.」即使移植正确但单次调用比原来更慢(调用 Rust 的开销超过节省的计算),也不会被启用。

--agent 参数接受 claude、codex,或「任何从 stdin 读取提示词的命令」;不带该参数时,可把 TASK.md 手动交给任意智能体。集成方式包括 Claude Code 插件、内置 MCP 服务器(暴露 fast_scan 到 fast_status 共 8 个工具),以及一个可教会任何智能体该流程的 skill 文件。每个移植都是单函数 crate,编译只需秒级,所有移植共享同一个 .fast/target 缓存目录。

README 报告的基准(i5-10500,Windows 11)显示:Python 模糊去重 116 倍,PHP 55 倍,Go 21 倍,Ruby 14 倍,C# 13 倍;Java(整体 3 倍,函数本身 11 倍,其余是 JVM 启动开销)、C(3.4 倍)和 C++(2.7 倍)提升较小。

为什么重要

README 对全量重写的反对理由很具体:「Rewriting a whole app in Rust costs months, minute-long compiles and gigabytes of target/. Most of the runtime sits in a few functions anyway.」(全量重写要花数月、分钟级编译和数 GB 的 target 目录,而大部分运行时间本来就集中在少数函数里。)fast-anything 把这个论断变成了闭环——剖析、移植、证明、切换——由编码智能体完成移植工作,但由工具框架在启用前强制验证行为等价性。

两个设计决定值得关注:

  • 移植最外层循环而非内部小函数。 工具「移植它能找到的最外层循环,而不是被其内部反复调用的小函数,让应用只跨越 Rust 边界一次,而不是数百万次」。README 指出,只移植内部的 levenshtein 时函数本身提速 35 倍,但整个应用只有 1.9 倍。

  • 接入护栏。 逐函数选择启用、逐字节可回退、基于真实录制调用的验证,以及性能门槛(更慢的移植会被拒绝),降低了生产环境采用 AI 生成代码的典型风险。

创建 1 天获得 1259 星的走势说明「智能体驱动、可验证、可回退的微重写」这一主张正在引起共鸣——不过这些数据还很早期,且基准成绩来自项目方自己。

对谁有影响

  • 解释型语言应用的开发者(Python、Node/TypeScript、Ruby,以及更广的语言矩阵),存在拖慢性能的热点函数。
  • 使用编码智能体的团队——Claude Code、Codex 或任何兼容 MCP 的工具(Cursor 被点名)——希望获得结构化、经过验证的任务而非自由发挥的重写。
  • 正在权衡「用 Rust 重写」的团队,现在可以对比逐函数精准移植与全量重写。
  • Rust 生态工具链(间接影响):npm 和 cargo 两个渠道均可安装,移植需要在本地有 Rust 工具链。

项目采用 MIT 许可证。安装只需一条命令(npm i -g @el4cteo/fast-anything 或 cargo install fast-anything),doctor 子命令可在开始前检查 Rust、运行时和智能体环境。

原文链接:GitHub - EL4CTEO/fast-anything。

全文翻译

GitHub 上的新仓库 EL4CTEO/fast-anything,创建 1 天,已有 1259 星(平均每天 1193 星)。 不要把它用 Rust 重写。重写那 5% 的慢速部分:对 Python、Node 或 Ruby 应用进行性能分析,使用你的编码代理将热点函数移植到 Rust,证明它们的行为一致。 主题:agent-skills, ai-agents, claude-code, claude-code-plugin, codex, developer-tools, ffi, mcp, mcp-server, napi-rs, nodejs, optimization, performance, profiler, pyo3, python, rewrite-it-in-rust, ruby, rust, typescript 语言:Rust

README:

不要把它用 Rust 重写。重写那 5% 的慢速部分。

将整个应用用 Rust 重写需要数月时间、分钟级的编译时间和千兆字节的 target/ 目录。实际上,大部分运行时间都集中在少数几个函数中。

fast-anything 会找到这些函数,让你的编码代理仅将它们移植到 Rust,证明移植后的代码在真实记录调用下产生相同的结果,并进行替换。一条命令完成,完全可逆。

安装

npm i -g @el4cteo/fast-anything      # 或者:cargo install fast-anything

端口通过你的 Rust 工具链(rustup)进行编译。

使用

fast-anything go --agent claude -- python app.py     # 或者:-- node app.ts / ruby app.rb / java App.java / mvn exec:java / gradle run / go run . / php app.php / clang -O2 main.c

或者逐步执行:

命令 作用
scan -- 对应用进行性能分析,按时间 × 可移植性对函数进行排名
port [id] 记录最多 500 次真实调用,创建一个单函数 Rust crate + TASK.md
verify 发布构建端口并重放所有记录的调用
enable / disable 切换 Rust 的启用或禁用状态(一个标记块,逐字节移除)
bench 对整个应用进行计时,原始版本与 Rust 版本交替运行
report 为你的 PR 生成 markdown + SVG 卡片
doctor 检查 Rust、你的运行时和代理

--agent 接受 claude、codex,或任何从 stdin 读取提示的命令。如果不提供它,手动将 TASK.md 交给你所使用的工具即可。

证明,而非感觉

那个端口看起来正确,但比较的是字节而不是字符。500 次真实调用中有 148 次发现了这个问题。除了记录的调用外,fast-anything 还会推导额外的案例并让原始代码回答它们:边界情况(NaN、±无穷大、-0.0、零和 ±1、非 ASCII 文本、空输入以及最大 16 倍大的输入)和缩小输入(微小和随机切片)。在所有情况下匹配之前不会启用任何内容:相同的值(浮点数误差在 1e-9 以内),错误时原始代码报错。如果每次调用的速度比原始代码慢(调用 Rust 的成本高于节省的工作量),也不会启用该端口。FAST_ANYTHING_DISABLE=1 始终运行原始代码。

结果

在 i5-10500、Windows 11(C 和 C++:4 核 GitHub Actions Linux 运行器)上的真实运行。从 examples/ 复现它们。

应用 之前 之后
Python 模糊去重(700 个名称) 4.91s 42ms, 116×
TypeScript 模糊去重(2,000 个名称) 3.11s 155ms, 20×
PHP 模糊去重(600 个名称) 2.94s 53ms, 55×
Go 模糊去重(3,000 个名称) 3.02s 144ms, 21×
Ruby 模糊去重(400 个名称) 3.13s 228ms, 14×
C# 模糊去重(4,000 个名称) 4.03s 312ms, 13×
Java 模糊去重(4,000 个名称) 3.50s 1.18s, 3×(函数内提升 11 倍;其余为 JVM 启动时间)
C mandelbrot(8 个缩放级别) 431ms 127ms, 3.4×
C++ 模糊去重(6,000 个名称) 3.02s 1.09s, 2.7×

fast-anything 移植它能找到的最外层循环,而不是内部调用的微小函数,因此应用只进入 Rust 一次而不是数百万次。仅移植内部的 levenshtein 函数得到了 35 倍和 1.9 倍的提升。

为什么不全部重写?

  • 编译时间:每个端口都是一个单函数 crate。秒级,而非分钟级。
  • 缓存:每个端口共享一个 .fast/target。随时可以删除它。
  • 风险:你的代码保持不变。Rust 是按函数选择的,并根据实际行为进行检查。

代理

  • Claude Code 插件:/plugin marketplace add EL4CTEO/fast-anything,然后 /plugin install fast-anything@fast-anything 和 /fast-anything:fast python app.py
  • MCP 服务器(Claude Code、Codex、Cursor…),内置于二进制文件中:claude mcp add fast-anything -- fast-anything mcp。8 个工具:fast_scan、fast_port、fast_verify、fast_enable、fast_disable、fast_bench、fast_report、fast_status。
  • 技能:skills/fast-anything 教给任何代理这个循环。

语言

语言 绑定 状态
Python 3.10+ PyO3 ✅
JavaScript / TypeScript (Node 22+) napi-rs ✅
Ruby 3.3+ C ABI + JSON,通过 Ruby 内置的 Fiddle ✅
Java 22+ (java App.java, Maven, Gradle) 相同的 C 桥接,通过 FF
查看原文

GitHub 上的新仓库 EL4CTEO/fast-anything,创建 1 天,已有 1259 星(平均每天 1193 星)。 Don't rewrite it in Rust. Rewrite the 5% that's slow: profile Python, Node or Ruby apps, port the hot functions with your coding agent, prove they behave the same. 主题:agent-skills, ai-agents, claude-code, claude-code-plugin, codex, developer-tools, ffi, mcp, mcp-server, napi-rs, nodejs, optimization, performance, profiler, pyo3, python, rewrite-it-in-rust, ruby, rust, typescript 语言:Rust

README:

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

Rewriting a whole app in Rust costs months, minute-long compiles and gigabytes of target/. Most of the runtime sits in a few functions anyway.

fast-anything finds those functions, has your coding agent port only them to Rust, proves the port gives the same results on real recorded calls, and swaps it in. One command, fully reversible.

Install

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

Ports are compiled with your Rust toolchain (rustup).

Use

fast-anything go --agent claude -- python app.py     # or: -- node app.ts / ruby app.rb / java App.java / mvn exec:java / gradle run / go run . / php app.php / clang -O2 main.c

Or step by step:

command what it does
scan -- profiles the app, ranks functions by time × how portable they are
port [id] records up to 500 real calls, creates a one-function Rust crate + TASK.md
verify release-builds the port and replays every recorded call
enable / disable swaps the Rust in or out (one marked block, removed byte for byte)
bench times the whole app, original vs Rust, interleaved runs
report markdown + SVG card for your PR
doctor checks Rust, your runtimes and your agents

--agent takes claude, codex, or any command that reads a prompt on stdin. Without it, hand TASK.md to whatever you use.

Proof, not vibes

That port looked right but compared bytes instead of characters. 148 of 500 real calls caught it. On top of the recorded calls, fast-anything derives extra cases and lets the original answer them: edge cases (NaN, ±infinity, -0.0, zero and ±1, non-ASCII text, empty and up to 16× bigger inputs) and shrunk inputs (tiny and random slices). Nothing is enabled until every case matches: same values (floats within 1e-9), errors where the original errors. A port that is right but slower per call than the original (calling into Rust costs more than the work saved) isn't enabled either. FAST_ANYTHING_DISABLE=1 runs the original any time.

Results

Real runs on an i5-10500, Windows 11 (C and C++: a 4-core GitHub Actions Linux runner). Reproduce them from examples/.

app before after
Python fuzzy dedupe (700 names) 4.91s 42ms, 116×
TypeScript fuzzy dedupe (2,000 names) 3.11s 155ms, 20×
PHP fuzzy dedupe (600 names) 2.94s 53ms, 55×
Go fuzzy dedupe (3,000 names) 3.02s 144ms, 21×
Ruby fuzzy dedupe (400 names) 3.13s 228ms, 14×
C# fuzzy dedupe (4,000 names) 4.03s 312ms, 13×
Java fuzzy dedupe (4,000 names) 3.50s 1.18s, 3× (11× on the function; the rest is JVM startup)
C mandelbrot (8 zoom levels) 431ms 127ms, 3.4×
C++ fuzzy dedupe (6,000 names) 3.02s 1.09s, 2.7×

fast-anything ports the outermost loop it can, not the tiny function called inside it, so the app crosses into Rust once instead of millions of times. Porting only the inner levenshtein gave 35× and 1.9×.

Why not rewrite it all?

  • Compile time: each port is a one-function crate. Seconds, not minutes.
  • Cache: every port shares one .fast/target. Delete it whenever you like.
  • Risk: your code stays as it is. Rust is opt-in per function, checked against real behavior.

Agents

  • Claude Code plugin: /plugin marketplace add EL4CTEO/fast-anything, then /plugin install fast-anything@fast-anything and /fast-anything:fast python app.py
  • MCP server (Claude Code, Codex, Cursor…), built into the binary: claude mcp add fast-anything -- fast-anything mcp. 8 tools: fast_scan, fast_port, fast_verify, fast_enable, fast_disable, fast_bench, fast_report, fast_status.
  • Skill: skills/fast-anything teaches any agent the loop.

Languages

language binding status
Python 3.10+ PyO3 ✅
JavaScript / TypeScript (Node 22+) napi-rs ✅
Ruby 3.3+ C ABI + JSON, through Ruby's built-in Fiddle ✅
Java 22+ (java App.java, Maven, Gradle) the same C bridge, through the FF

原文版权归 GitHub 爆发仓库 及原作者所有,本站转载仅供阅读。如需删除,请联系 support@aisa.one。