破碎的心
Or, getting a 100x speedup with one dumb line of code.
或者,用一行愚蠢的代码获得 100 倍加速。
January 31, 2026 • 7 min read
2026 年 1 月 31 日 • 7 分钟阅读
You always know it’s a good bug when your first reaction is, “How could this even happen?”
当你的第一反应是,“这怎么可能发生?”时,你就知道这是一个好 bug。
The other day, I was refining the dashboard of a web app we’re working on – as you do – and I noticed it was taking forever to load. Like, it had been loading in a single second, but now it was taking ten seconds. Something fishy was going on.
前几天,我正在优化我们正在开发的一个 web 应用的仪表板——就像你会做的那样——我注意到它加载超级慢。比如,它之前一秒钟加载,现在要十秒钟。有什么可疑的事情在发生。
Naturally, I blamed React.
自然而然,我把问题归咎于 React。
I mean, sure, in a modern web app there are many potential causes of a performance problem: third-party JavaScript, overburdened servers, bloated assets, missing database indexes – a list as long as your arm. But decades of building for the web told me that this was a frontend problem. I could just smell it. The page looked janky while loading. And despite being the least-bad approach for web frontends today, the React ecosystem is lousy with ways for a codebase to get tangled, slow, and fishy.
我的意思是,当然,在现代 web 应用中,性能问题的潜在原因有很多:第三方 JavaScript、负载过重的服务器、臃肿的资源、缺少数据库索引——长到你手臂那么长的列表。但几十年的 web 开发经验告诉我,这是一个前端问题。我就是能闻出来。页面加载时看起来很卡顿。尽管是当今 web 前端最不坏的方法,React 生态系统充满了让代码库变得纠缠、缓慢和有问题的途径。
So to prove my theory, I explained to Claude1 that the dashboard was loading slowly, that it surely had some React problems, and to analyze it and rank them from most to least serious. And sure enough, Claude found a bunch of React fishiness – unnecessary re-renders, missing memoizations. We still weren’t on React Compiler, which I hadn’t realized. So I had Claude do a first pass on the easiest and most serious React issues, and…
所以为了证明我的理论,我向 Claude1 解释说仪表板加载缓慢,它肯定有一些 React 问题,并让它分析并按从最严重到最不严重排序。果然,Claude 发现了一堆 React 的可疑问题——不必要的重新渲染、缺少 memoization。我们还没有使用 React Compiler,这是我没有意识到的。所以我让 Claude 对最简单和最严重的 React 问题进行第一遍处理,然后…
It made almost no difference? Maybe it wasn’t React after all.
几乎没有区别?也许根本不是 React 的问题。
So, I rolled up ...