The app wasn't slow because of one thing. It was twenty.
On 29 October, a bar wrote to us: the app was slow. Especially on old Android phones, and on the Till screen.
PilloSitio is the app we built so bars can run bookings, menu, orders, till and delivery in one place. We built it, so it was our fault too. And if it's slow at rush hour, it isn't an annoyance. It's a queue.
PilloSitio had to reach the market as soon as possible. First, make it work. Then, make it fly. Optimising with no bars using it would have been optimising blind.
So part of the slowness was our choice: not optimising at the start. The rest was our own mistakes. Here are both.
Three days later, in our tests, every screen opened in just over a tenth of a second. There wasn't one culprit. There were twenty.
First, measure: the performance audit
Faced with a slow app, the temptation is to pay for a bigger server or rebuild it from scratch. Both cost money. And neither fixes anything if you don't know what's wrong.
So, before touching anything, an audit. Read-only: look, count and write it down, as in a technical due diligence. Four fronts: what travels over the network, the server, what the app downloads on start-up and how each screen draws.
We counted the server calls behind every gesture. Starting the app for a bar with 30 tables: about 40. Creating an order: between 12 and 16, five of them one after another.
- 01
Network
A 0.5 s toll before every call.
Now: once every 2 hours.
- 02
Server
Full cache and 228 queries for 50 orders.
Now: 99.96% hit rate and 29 queries.
- 03
Start-up
3.2 MB of code, 15 MB of icons and 72 fonts.
Now: 1.45 MB, 0.5 MB and 12 fonts.
- 04
Rendering
Every event recalculated the whole app.
Now: only what changes gets redrawn.
Configuration: half a second and a full cache
Every call paid a toll. Before asking for anything, the app checks with the server that it's allowed to. The normal thing is to keep that answer for a while. Here, one line of configuration said never to keep it. Half a second more on every call. We fixed it by changing a number: now it's kept for two hours.
And the cache where PHP keeps code ready to run was full: 128 MB, with 1 KB free. One attempt in four started from scratch. Enlarging it and storing the Laravel configuration ready-made too took it from a 76% hit rate to 99.96%.
The biggest jump was the cheapest: without touching a line of the app. While we were at it, we compressed the large responses. The Till one went from 1.75 MB to 130 KB.
From 2,363 queries to 32: the N+1 problem
The orders list had a textbook mistake. For every order, the server asked the database, one by one, for each user's permissions. With 50 orders, 228 queries. With all of a bar's orders, 2,363. Developers call it the N+1 problem.
Now they're fetched in one go: 29 queries with 50 orders, 32 with all of them. The full list dropped from 1.25 seconds to about 0.4.
Less code when the app opens
The bars' app downloaded all 35 of its screens on start-up: 3.2 MB of code. Now each screen loads when it's needed, and the everyday ones preload in the background. 1.45 MB.
The icons weighed 15 MB. One was 8,920 pixels wide, and it was in there twice. Now they weigh half a megabyte.
And every screen change had a fixed 800-millisecond fade. Pretty, yes. But at rush hour, 800 ms per tap adds up to a lot of taps. Gone.
If you're starting a mobile app, this gets decided on day one. Not on the day the bar complains.
Redraw only what changes on screen
Every tap, every second of a timer and every real-time notification made the app recalculate all of its screens. We moved some 160 pieces to redraw only when their data changes.
The risk: if data changes without saying so, the screen freezes and nobody notices. So we went from the small pieces to the big ones, with a test for every fix and an alarm in development that goes off the moment it happens. It found bugs that were already there.
No spinner: not waiting for the server
On 31 October, a video arrived of the bar using the app. It showed what no number tells you: a waiter staring at a loading spinner.
So we changed the approach. Each screen shows the last thing it saw straight away and catches up quietly. Simple actions, like freeing a table or marking a dish as ready, apply instantly. And if the bar's connection drops at that exact moment, the screen goes back to how it was. Nothing is left half-done.
Measured locally: a screen opened cold appears in 108 to 129 milliseconds, no spinner. Freeing a table, 4 ms. A new order shows up in the list in under a tenth of a second.
“Anything that moves money doesn’t get faked.”
Payments and the till: no shortcuts here
One rule ran through the whole job. Creating an order, taking payment, refunding, applying a discount or closing the till still wait for the server's answer. No shortcuts there: the server decides the total, not the screen.
Before and after, in numbers
The numbers, side by side.
| Measure | Before | Now | Change |
|---|---|---|---|
| Queries for the orders list (all) | 2,363 | 32 | −99% |
| Time for that list | 1.25 s | ~0.4 s | −68% |
| 0.5 s toll before every call | Every time | Once every 2 h | |
| Server cache hit rate | 76% | 99.96% | |
| Till response | 1.75 MB | 130 KB | −93% |
| Code on start-up (bars' app) | 3.21 MB | 1.45 MB | −55% |
| Code on start-up (customers' app) | 1.78 MB | 1.03 MB | −42% |
| App icons | 15 MB | 0.5 MB | −97% |
| Fade between screens | 800 ms | 0 | −100% |
| Calls to close the till | 3 | 1 | −67% |
What a slow app teaches you
Slowness is almost never one problem. It's lots of small ones, added up. And the ones that pay off most tend to be the most boring: a line of configuration, a full cache, a repeated query.
Along the way, we updated the libraries of both apps and the server, and several known vulnerabilities went with them. Fast and secure aren't two separate projects. That's why updates are part of app maintenance, from €100 a month.
Is your app slow and nobody knows why? Write to us. We measure first. Then we tell you what's wrong and what it costs to fix. And if what you want to hear is that it's the old phones' fault, we're not your studio.