Engineering · Performance · The back office

A screen that asked again after each draw

The commission page took nearly four seconds and its slowest call one and a half. The rest was the screen waiting to draw before asking its next question.


Our speed board lists every screen anybody opened, slowest first, with the one call that took longest beside it. Most rows make sense at a glance: the screen took about as long as its worst call, give or take the drawing. The commission screen did not. Three loads, 3,815 milliseconds on average, and its slowest call was 1,449. More than half the wait was not any call at all.

That gap is a shape we have learned to read. A screen that takes far longer than its longest request is a screen that is asking its questions one after another and drawing in between.

Three waves

The commission screen opens on the rates, the markets and the companies, all at once, and draws the picker. Then, once the picker is on the page, it asks for the month's statement for the first kitchen and draws that. Then, once the statement is drawn, it asks for the delivery statements and draws those. Three waves, each waiting for the one before, and each a full round trip from a browser in Winchester to a worker in London to a database in Virginia and back.

None of the three later questions depended on the earlier answers. The screen opens on the first kitchen in the picker and the current month, and that is known before anything has been fetched. The statement could have been asked for in the same breath as the rates.

Ask before you wait, take when you need

The fix is small and it is a pattern worth naming. Before the screen's first wait, it starts the statement request and the delivery request for the kitchen and month it will open on, and keeps hold of the promises. The first draw happens as before. When the draw reaches the statement, it takes the promise it already holds instead of starting a new request. Same for delivery. If the operator changes kitchen or month, those are fresh questions and are asked fresh. The two later draws now run together rather than one behind the other.

A test reads the screen's source and pins the shape: the two promises are created before the first wait, taken once, and the serial pair is gone. It failed on the old code by name.

The server side of the same release took a hop out of the statement route itself, and that is its own story. But even with a perfect server, a screen that draws three times in series pays three round trips, and from the far side of an ocean each of those is a tenth of a second on a good day and half a second on a bad one. The board had been telling us that for a week. We had been reading the slowest-call column and not the gap beside it.


Try it on tonight’s service.

Nothing to install, no card. Not better by the weekend? Close the tab.