What to Measure First When Your App Feels Slow

· 5 min read ·

A young man in a green sweater holds a clipboard and looks puzzled at a queue of customers, while a small white robot with a stopwatch times each one

In August 2009, David Heinemeier Hansson wrote a short post called The problem with averages. Basecamp’s average response time was 87 milliseconds, said the dashboard. Fantastic, except he warned that an average like that can hide a disaster, with a hypothetical: a thousand super-fast cached replies can bury requests that take two full seconds behind a healthy-looking mean. The arithmetic is unforgiving: 1000 requests at 5ms plus 50 requests at 2000ms averages to exactly 100ms, a number any dashboard would call healthy, while every one of those 50 users, about one in twenty, had a product that felt broken.

That is why “my app feels slow” sends most people to the wrong fix. You cannot fix slow. You can only fix a slow something, and your job is to find its name before you touch any code.

The order that works

Measure in this order, cheapest first, and stop the moment the culprit has a name:

1. Is it the server or the browser? One curl answers this: curl -o /dev/null -s -w 'server: %{time_starttransfer}s total: %{time_total}s\n' https://your-app.example/feed. One caveat: the server number includes DNS, TLS, and network time, and for a far-away user that can be most of it, so add connect: %{time_connect}s to see how much is really your backend. If the server time is the bulk of the total, the problem is your backend. If the server answers fast but the total is slow, the problem is the page itself: images, scripts, layout, the things that break when your app meets real users.

2. Which route is slow, at the bad end, not on average? This is DHH’s lesson. Group response times by route and look at the 95th percentile of each: the experience of your unluckiest regular visitors. You do not have to build this to look at it: Vercel’s Observability tab shows p75 and p95 per route, Supabase has a Query Performance report for slow SQL, and Cloudflare Web Analytics reports real-visitor page-load percentiles. The average is a lullaby.

3. Inside the slow route, which step eats the time? Wrap each step (the database query, the external API call, the heavy computation) in a timer and log the breakdown for a while. Often the answer is one database query, and the fix is an index or a missing join, which is exactly the territory of why your app gets slower with every new user and the N+1 query problem.

Only now are you allowed to optimize. Notice what you did not do: rewrite the framework, add a cache, or buy a bigger server. Those are the three most common guesses, and all three are expensive ways to leave the real bottleneck untouched.

Prove it with runnable tests

Save this as test_measure_first.py in an empty folder and run python3 test_measure_first.py. It builds a tiny two-route app (a fast feed and a slow report), drives traffic through it, and shows what two kinds of monitoring can see, plus a drop-in timer you can wrap around the steps of your own slow route. Standard library only.

"""Behavior tests for measuring a slow app before fixing it. Run: python3 test_measure_first.py"""
import time
import unittest
def fake_db_query():
time.sleep(0.18) # the expensive report query
def route_feed():
time.sleep(0.005)
return "feed items"
def route_report():
fake_db_query()
time.sleep(0.005) # rendering
return "monthly report"
def run_traffic(monitor):
for _ in range(20):
monitor.record("/feed", route_feed)
for _ in range(5):
monitor.record("/report", route_report)
class AverageMonitor:
"""Records only the fleet-wide average, the way most dashboards start."""
def __init__(self):
self.times = []
def record(self, route, handler):
start = time.perf_counter()
handler()
self.times.append(time.perf_counter() - start) # route name discarded
def average(self):
return sum(self.times) / len(self.times)
def slow_routes(self, limit=0.1):
# All it can answer is whether the fleet average looks bad.
if self.average() > limit:
return ["something is slow, but it never learned any route names"]
return []
class RouteMonitor:
"""Records each route separately, so the slow one has a name."""
def __init__(self):
self.by_route = {}
def record(self, route, handler):
start = time.perf_counter()
handler()
self.by_route.setdefault(route, []).append(time.perf_counter() - start)
def slow_routes(self, limit=0.1):
return [r for r, ts in self.by_route.items() if p95(ts) > limit]
def p95(times):
ordered = sorted(times)
return ordered[min(len(ordered) - 1, int(len(ordered) * 0.95))]
def time_step(name, fn, log):
"""Drop-in timer: wrap each step inside a route, get one line per step."""
start = time.perf_counter()
result = fn()
log.append((name, time.perf_counter() - start))
return result
def route_report_timed(log):
time_step("database", fake_db_query, log)
return time_step("rendering", lambda: time.sleep(0.005) or "monthly report", log)
# Which monitor the app uses. FIX (after the first run): point it at RouteMonitor.
MONITOR = AverageMonitor
class MeasureFirstTests(unittest.TestCase):
def test_the_slow_page_has_a_name(self):
dashboard = AverageMonitor()
run_traffic(dashboard)
self.assertLess(dashboard.average(), 0.1,
"the fleet average should look healthy; that is the trap")
monitor = MONITOR()
run_traffic(monitor)
self.assertIn("/report", monitor.slow_routes(),
"the slow page is invisible in the metrics")
def test_the_step_timer_logs_one_line_per_step(self):
log = []
route_report_timed(log)
self.assertEqual([name for name, _ in log], ["database", "rendering"])
slowest = max(log, key=lambda kv: kv[1])[0]
self.assertEqual(slowest, "database")
def test_fast_pages_are_not_blamed(self):
monitor = RouteMonitor()
run_traffic(monitor)
self.assertNotIn("/feed", monitor.slow_routes())
if __name__ == "__main__":
unittest.main()

The first run reproduces the mirage:

FAIL: test_the_slow_page_has_a_name (__main__.MeasureFirstTests)
AssertionError: '/report' not found in [] : the slow page is invisible in the metrics
Ran 3 tests in 3.273s
FAILED (failures=1)

Read the failure carefully, because it is the whole lesson in one run. The test first asserts the fleet average stays under the slow line, and that part passes: twenty 5ms requests and five 185ms ones average to 41ms, which looks healthy. In that same run, the average monitor cannot name the slow page, because it never recorded one. The two passing tests matter too: the step timer logs one line per step and names the database, and fast pages are never blamed, because once you know where to look, looking is easy. Now flip the one marked line to RouteMonitor and run again:

Ran 3 tests in 3.271s
OK

Swap the toy monitors for a real metrics library and the same three bars still have to hold: the slow page gets a name, the step timer logs one line per step, fast pages are left alone. Their limit: they protect the habit of measuring by route and by step. They say nothing about which fix the database step needs; that is what the measurement is for.

The hand check: one evening of timestamps

Pick your app’s most important route and add three timestamps to its logs tonight: request arrived, database answered, response sent. Tomorrow, sort that route’s requests by total time and read the slowest five. If the gap between “arrived” and “database answered” is most of it, you know which post to read next. If the gap is after the database answered, the time is in your code or a third-party call, and the same three-timestamp trick moves one level deeper.

The prompt to paste

Add timing instrumentation to this app, no behavior changes. For every route, log the route name, the total duration, and the duration of each major step inside it (every database query, every external API call, every loop over more than a hundred items). Then show me a slow request’s full timeline from the logs, with the slowest step highlighted. Do not optimize anything yet.

Feeling slow before you can prove slow is one of the six things that break when your app meets real users. Measure first; the fix is usually smaller than the fear.

The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.

Comments