7 min

The cheapest millisecond is the one you never spend

Most of a slow checkout is work nobody asked for. How to find it before you buy a bigger machine.

Idris Halloran

Software engineer, Edinburgh

When a page is slow, the first suggestion is usually a bigger machine. It is rarely the cheapest fix and almost never the first one to try.

Trace one request

Pick a single slow request and follow it from the click to the last byte. Write down every hop and how long it took. On Fernhill's checkout that list had eleven lines, and three of them were the same lookup.

Delete before you tune

The fastest query is the one that is not sent. Most of the 840 milliseconds went on work whose answer was already in memory two functions up the stack.

// before: three round trips per payment
const shop = await db.shop(id)
const plan = await db.plan(shop.planId)
const rate = await db.rate(plan.rateId)

// after: the ledger row already carries the rate
const { rate } = payment
// before: three round trips per payment
const shop = await db.shop(id)
const plan = await db.plan(shop.planId)
const rate = await db.rate(plan.rateId)

// after: the ledger row already carries the rate
const { rate } = payment
// before: three round trips per payment
const shop = await db.shop(id)
const plan = await db.plan(shop.planId)
const rate = await db.rate(plan.rateId)

// after: the ledger row already carries the rate
const { rate } = payment

Keep the ruler

Leave the measurement in place when you are done. A number that is on a screen every morning tends to stay where you put it.

Next

Next

What a double-entry ledger taught me about state

What a double-entry ledger taught me about state

Have a number that needs moving? Tell me what it is today.

Next free in January 2027. Send the number, where it is measured, and what it costs you. I reply within a day.

Next free in January 2027. Send the number, where it is measured, and what it costs you. I reply within a day.

Create a free website with Framer, the website builder loved by startups, designers and agencies.