5 reasons your AI-built app is slow
The short version
Five real causes of slowness, all of them found in one app, none of which require rewriting anything. The largest by far was geography: the server and the database were on different continents, which cost four seconds on open and was fixed by moving one of them.
The others: cold starts making one unlucky user pay the wake-up cost, a supposedly faster component that measured slower, a twelve second win from simply reordering two calls, and a user interface that waits for the server instead of showing the result immediately.
Work through them in order. The first one is usually the biggest and the cheapest to fix, and it is the one nobody checks because it does not look like a code problem.
1. Your app and its memory live on different continents
What happened to me: the app ran in America. Everything it remembers about you sat in Singapore. Fifteen thousand kilometres apart, so every single tap flew across an ocean and came back. Four seconds just to open. I was about to rebuild the whole thing before I found it.
How you would know: your app is slow at everything, evenly, rather than slow at one particular screen. Speeding up individual actions barely helps.
The fix: move one of them so they sit together. No code changes. Mine went from four seconds to half a second.
Tell me which physical region each part of my app runs in: the server, the
database, the cache, and file storage. Put them in a table side by side and
flag any that are not in the same region as the server. Then estimate how much
time a single user request spends purely travelling between them, and tell me
whether moving one of them is the cheapest speed win available to me right now.
2. Your app falls asleep, and the first person to arrive pays to wake it
What happened to me: most cheap hosting puts your app to sleep when nobody is using it. The next person to show up waits for it to get out of bed, and that wait is added to whatever they were trying to do.
How you would know: the app feels fine when you are testing it repeatedly, and slow when a real person opens it after a quiet hour. That is the worst possible split, because you will never reproduce it.
The fix: know what the wake-up actually costs before you decide whether it matters. Do not paper over it with something that keeps the app permanently awake, because that is expensive (see the money pack).
Does my app go to sleep when it is idle, and if so, what does the very first
request after that cost in seconds? Measure it rather than estimating. Then
tell me what fraction of my real visits are likely to land on a cold start,
and what my options are ranked by cost to me per month.
3. The thing you added to make it faster is making it slower
What happened to me: I swapped a component for the newer version that was supposed to be faster. It was slower. I only found out because I measured both, and I had a habit of measuring. It also quietly broke my ability to see where time was going, which is worse than being slow.
How you would know: you cannot know. This one is invisible without a measurement, which is the entire point of it.
The fix: benchmark on your own app with your own data, not on somebody else's blog post. And treat "can I still see what is happening" as a feature you are allowed to refuse to give up.
List everything I have added to my app specifically for performance. For each
one, tell me whether I have ever actually measured it against the thing it
replaced, on my own workload. Where I have not, show me the smallest way to
run that comparison. Also flag anything that reduced my ability to see where
time is being spent.
4. The order you do things in
What happened to me: I changed nothing except which of two things went first. Twelve seconds faster. Then I added two more of the same kind of thing expecting it to get better again, and it got worse, so I removed them the same week.
How you would know: one action in your app is dramatically slower than everything else, and it involves waiting on more than one outside service.
The fix: find things that wait on each other for no reason. If B does not need A's answer, they can both go at once.
Find every place in my app where I wait for one thing to finish before starting
the next, and tell me which of those actually need the first result. For the
ones that do not, show me how to start them at the same time instead. Then
tell me which single action in my app spends the most time waiting rather than
working.
5. Your app waits for the server before it shows anything
What happened to me: the fix here is free and it is mostly a decision, not code. When someone taps something, you can show the result immediately and quietly send it in the background, then correct it in the rare case it fails.
How you would know: every tap in your app has a small dead moment before anything visibly happens.
The fix: show first, confirm after. But be careful with this one: if you show something before it saved and then never check, you get the disappearing-data bug (see the silent-failures pack). Show immediately, and still handle the failure.
List every action where my app waits for a server response before updating the
screen. For each, tell me whether it could update immediately and reconcile
afterwards. Then show me exactly how I would handle the case where the server
later rejects it, so nothing silently disappears for the user.
Steal this for your app
- Do them in order. Geography first, then cold starts, then everything else. Most people work that list backwards and start by optimising individual actions, which is the smallest win available.
- Measure before and after every single one, or you will end up like number three: confidently slower.
- None of these need you to write code yourself. They need you to know to ask.
Part of the "What It Cost Me" series. Every item above is something that actually happened while building my app.