Or, getting a 100x speedup with one dumb line of code.
You always know it’s a good bug when your first reaction is, “How could this even happen?”
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.
Naturally, I blamed 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.
So to prove my theory, I explained to Claude 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…
It made almost no difference? Maybe it wasn’t React after all.
So, I rolled up my sleeves, and started investigating properly.
Maybe the server really is slow? A little, but it’s not blocking the frontend. Was the problem in all browsers? No. It was somehow specific to Safari? Ah, it must be third-party JavaScript then. Intercom? No. PostHog? No. Okay, let’s really dig in to the performance timeline.
Now, the Safari performance inspector has diverged from the Chromium one over the years, and has gotten (on this page at least) rather flaky. But it painted a pretty clear picture: It wasn’t spending 7+ seconds parsing JavaScript, calculating styles, or loading from the network. It was using 94% of an M1 Max CPU on… Layout?
... continue reading