Build Log

Breaking Down "Sometimes Fast, Sometimes Slow" With Numbers

Three bars compared by length — cached 108ms, 10Mbps 634ms, 4Mbps 1291ms

The site was sometimes fast, sometimes slow. Even loading the exact same page.

Symptoms like this have too many candidate causes. You can't tell whether the server is unstable, whether it's the network, what state the cache is in, or whether it's just your imagination. So the first step was turning the feeling into numbers.

The measuring rig

Opening browser dev tools by hand and timing things manually means the conditions change every time. Whether the cache was cleared, when you happened to open the Network tab, what other tabs were downloading in the background — it all gets mixed together.

I attached to headless Chrome over CDP and pinned the conditions down.

await send('Network.setCacheDisabled', { cacheDisabled: true })
await send('Network.emulateNetworkConditions', {
  offline: false,
  latency: 40,
  downloadThroughput: (10 * 1024 * 1024) / 8,  // 10Mbps
  uploadThroughput: 262144,
})
await send('Page.navigate', { url })

This way I decide the cache state and the connection speed. Every run starts from the same baseline.

First question: is the server unstable?

With conditions held completely fixed, I ran it four times.

Run Total load
1 2,659ms
2 2,641ms
3 2,652ms
4 2,648ms

Variance was under 1%. The server wasn't the unstable part.

Second question: so what was unstable?

I measured again, this time only changing the conditions.

Condition Total load
Cache hit 104ms
10Mbps · no cache 2,650ms
4Mbps · no cache 6,214ms

A 60x difference. This was the real identity of "sometimes fast, sometimes slow." It wasn't the server — it was entirely the viewer's cache state and connection.

Once I got here, the next step was obvious. There was nothing to fix on the server — I needed to cut down how much was being transferred.

Two times my own measurements lied to me

I did the work to cut payload size and reported "after" numbers. Twice, those numbers turned out to be wrong.

Measuring locally proves nothing

After making the fix, I measured locally and wrote down that it got faster. The feedback I got back was:

Local rendering is already fast, so there's not much difference, is there

They were right. Locally, there's no bandwidth cap. What I'd reduced was transfer size, but measuring in an environment where transfer time is near zero means that reduction never shows up. It wasn't that things looked faster — they were already fast to begin with.

The only thing that stayed valid was the byte count. I re-measured timing with the same throttling applied again.

If the ranking flips, the measurement is broken

Measuring again produced this table.

Connection Total load
4Mbps 4,280ms
10Mbps 8,805ms
30Mbps 7,901ms

The faster connection was slower. This isn't a "surprising result" — it's a sign the measurement itself is broken. A slower connection cannot outperform a faster one.

The cause was in the machine doing the measuring. That MacBook was resolving the domain over IPv6, and that route was flaky. Pointing curl at IPv4 directly connected fine.

Re-measuring the same deployment over a different address came out normal.

Connection Broken route Healthy route
4Mbps 4,280ms 2,312ms
10Mbps 8,805ms 625ms

What's left

Two lessons from this round of performance measurement.

One. When a symptom shows high variance, pin down the conditions one at a time before trying to narrow the cause. The moment four runs under identical conditions landed within 1% of each other, the server was off the suspect list.

Two. When a measurement contradicts common sense, question the measurement before trying to explain the result. If I'd looked at a table showing 10Mbps slower than 4Mbps and shrugged it off as "must be some edge routing thing," I would have ended up fixing the wrong thing entirely.