The FieldHub's pages were arriving cut short and sometimes stalled for five seconds on a phone. After a day of measuring and small fixes they arrive whole in about 0.2 s, and the firmware image went from 94.6 % to 84.0 % of its slot.
FieldMesh3 min readfieldhub, firmware, performance, web
The hub serves its own pages over its own Wi-Fi, from a microcontroller with very little spare memory. After a few weeks of adding features it felt slow on a phone, so I measured before changing anything.
The first measurement showed that most pages weren't arriving whole. Each page was built as one string that grew in small pieces, and on a fragmented heap the string silently stopped growing, so the page lost its last sections. On an iPhone, 8 of 9 page loads were cut short. Reserving the page's memory in one go fixed that. The next problem was a stall: 4 of 10 loads waited about 5 s before the first byte. The hub serves one connection at a time, and the browser had opened a connection ahead of time and sent its request on another, so the hub sat waiting on the idle one. Closing a connection that has sent nothing for half a second, when another is waiting, removed the stalls.
Then the pages themselves. Nearly every page carried the same 47 KB of CSS and JavaScript, so those are now served once as compressed, cached files, and pages went from roughly 55–63 KB to 7–16 KB. Reading the upload settings once per page, dropping two extra requests per load and a shorter sleep in the request loop did the rest. The median briefly got worse along the way, from 0.37 s to 0.62 s, because with smaller pages the half-second idle wait became most of a load. Cutting it to 0.1 s brought the median to 0.2 s, and the slowest load of the last run took 0.33 s.
Time until a hub page was ready on the phone across four bench runs. Each dot is one page load; the line is the median.
Two of those changes also freed flash. Compiling without C++ exceptions, which nothing in the hub uses, saved 130 KB, and the shared files saved another 34 KB. The firmware image went from 94.6 % to 84.0 % of its slot, which leaves room for the SD storage and update work that follows.
These are bench numbers from one hub and one phone, an iPhone SE, with 10 to 12 page loads per run. The setup wizards still carry their own scripts, and the overview still takes 120–160 ms to build because it counts waiting readings by reading a whole file. That goes away once uploads read from the SD card.