# 别重写 Rust，只优化那 5% 慢代码

Original title: Fast-Anything: Don't rewrite it in Rust. Rewrite the 5% that's slow

> Hacker News story 50596155 · language: zh · submitted 2026-11-22
> Web version: https://zeli.app/zh/story/50596155
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 171 · by [BaselAshraf81](<https://news.ycombinator.com/user?id=BaselAshraf81>) · 💬 134
[original](<https://github.com/EL4CTEO/fast-anything>) · [HN discussion](<https://news.ycombinator.com/item?id=50596155>)

## Summary

把整个应用重写为 Rust 往往耗时数月，还要忍受漫长的编译和巨大的构建产物。fast-anything 提出更务实的方案：通过性能分析定位那 5% 的热点函数，利用 Claude Code 等编程代理仅将这些函数移植到 Rust。工具会记录真实调用进行验证，确保行为完全一致后才切换。实测显示，Python、Node、Ruby 等应用的性能可提升数十倍，且无需重写整个项目。

## Key quote

> 不要把它重写为 Rust，只重写那 5% 慢的部分。

## HN discussion (134 comments)

### [zodwick](<https://news.ycombinator.com/item?id=50599553>)

> 我想反驳一下：如果从一开始就带着性能意识重写，哪怕是用同一种语言，也能让大多数代码库提速 50%。
>
> 以 Python 为例，重写同一个应用时，我们可以利用后见之明，从一开始就做出更好的决策（将慢的部分卸载到 C 二进制文件、优化数据结构选择、消除冗余等等）。这其实也是程序被重写到另一种语言（比如 Rust）时发生的情况——从一开始就做出更好的决策，并且不会把冗余代码照搬过来。
>
> 当然，这显然有例外。但大多数情况下，让程序变慢的是我们做出的选择，而不是语言本身。
>
> 过去，由于重写需要付出巨大努力，重写程序几乎总是一个愚蠢的主意——参见：https://www.joelonsoftware.com/2000/04/06/things-you-should-...。但在我的观点里，AI 让这种论点不再那么有说服力了。我现在经常让 AI 代理根据给定的各种目标，重写程序的大部分内容。

### [ThouYS](<https://news.ycombinator.com/item?id=50598795>)

> 挺有意思，但根据我的经验，能用这种方式解决的瓶颈都是些容易摘取的果实，很快就会被优化掉。
>
> 真正的性能杀手更像沙子，散布在整个系统中，无处不在。

### [hendler](<https://news.ycombinator.com/item?id=50597812>)

> 用 Rust 重写也是完全可以的，因为这不仅仅是为了性能。其他语言（如 Python、Ruby 等）中快速的部分可能本身就是用 C/C++ 写的，或者调用了外部库，而这些部分往往也是存在漏洞的薄弱环节。

### [alexfromapex](<https://news.ycombinator.com/item?id=50600839>)

> 直到我用 Rust 重写，我才意识到 psycopg2 在 Python 中的速度和 Rust 的数据库调用差不多快，因为它全部是用 C 编译的。我之所以必须彻底重写，是因为我的代码要部署在客户机器上，我不想让他们窃取知识产权。速度、稳定性和安全性的提升只是额外的红利。

### [osigurdson](<https://news.ycombinator.com/item?id=50600252>)

> 我做了一个实验，看看能把桌面 Linux 应用做得多小、多高效。我学到的一个教训是：对于非常基础的应用，GPU 带来的内存开销很大，但收益却微乎其微。

### [the_arun](<https://news.ycombinator.com/item?id=50600908>)

> Java - “1.18 秒，3 倍（函数内部为 11 倍；其余是 JVM 启动时间）”——为什么要把 JVM 启动时间算进去？我们不能假设 Java 已经启动了吗？我们不会为每个函数都启动 JVM，对吧？

### [diegocg](<https://news.ycombinator.com/item?id=50597503>)

> 更好的做法是：别再用那些会有性能问题的语言去编写大型代码库了。

### [tialaramex](<https://news.ycombinator.com/item?id=50598547>)

> 注意，这个策略只有在你的软件中只有 5% 是问题所在时才有效——因为阿姆达尔定律（Amdahl's law）。

---

## Cite

- Page: https://zeli.app/zh/story/50596155
- Date: 2026-11-22
- Source: github.com (https://github.com/EL4CTEO/fast-anything)
- Hacker News: https://news.ycombinator.com/item?id=50596155

## Other languages

- en: https://zeli.app/story/50596155 · markdown: https://zeli.app/story/50596155.md
- ja: https://zeli.app/ja/story/50596155 · markdown: https://zeli.app/ja/story/50596155.md
- ko: https://zeli.app/ko/story/50596155 · markdown: https://zeli.app/ko/story/50596155.md
- de: https://zeli.app/de/story/50596155 · markdown: https://zeli.app/de/story/50596155.md
- es: https://zeli.app/es/story/50596155 · markdown: https://zeli.app/es/story/50596155.md
- ru: https://zeli.app/ru/story/50596155 · markdown: https://zeli.app/ru/story/50596155.md
