Code that works at n = 10 can fall over at n = 10,000,000.

Live pictures of what happens in between.

latency now 20ms
p99, last 10 s 20ms
healthy
A simulated server answering requests, live. The line is how long each request takes to come back, in milliseconds, newest on the right. Most answer in about 20 ms; every few seconds a burst of traffic piles up faster than the server can clear it, so requests wait in line and the line shoots up, then drains. The chip reads healthy up to 50 ms, degraded up to 100 ms, and spiking above that.

When the data grows

Five common shapes of code, timed as the input grows from 10 items to 10 million. Each line is how long the work takes: the flat ones stay instant forever, the steep ones stop finishing.

Assumes one operation = 10 ns

Input size n

op 10 ns n up to 10M

  • O(1)
  • O(log n)
  • O(n)
  • O(n log n)
  • O(n²)
ClassWhat it looks like in codeOperationsWall timeStatus
O(1)a hash lookup, an array index110 nsinstant
O(log n)binary search, a B-tree index probe333.2 nsinstant
O(n)one pass, a full table scan10100 nsinstant
O(n log n)merge sort, an ORDER BY with an index33332 nsinstant
O(n²)a loop inside a loop, includes() in a map1001 µsinstant

Sorting a list, five ways

The same 48 numbers sorted by five methods, running for real side by side. Every lane gets the same number of steps per second, so the method that needs fewer steps finishes first, and the slow ones are still grinding long after the fast ones are done.

Real steps, counted as they happen: comparisons, or digit moves for radix sort, which never compares two numbers

Steps per second
Bubble sort O(n²) 0 comparisons sorting
Insertion sort O(n²) 0 comparisons sorting
Quick sort O(n log n) 0 comparisons sorting
Merge sort O(n log n) 0 comparisons sorting
Radix sort O(n) 0 digit moves sorting

sorting 48 numbers table 1,000,000 step 10 ns

The same five methods on a list of 1,000,000, at 10 ns per step
MethodStepsTime
Bubble sort5 × 10¹¹ comparisons1.39 h
Insertion sort2.5 × 10¹¹ comparisons41.7 min
Quick sort2.77 × 10⁷ comparisons277 ms
Merge sort1.99 × 10⁷ comparisons199 ms
Radix sort1.4 × 10⁷ digit moves140 ms

Loading a page from the database

One page with 3 lists on it, where every row needs a related record (say, each order's customer). Lazy loading fetches that record separately for every row: the N+1 query an ORM makes easy to write. The other three fetch the same data in a handful of trips, whatever the row count.

Assumes each database query costs a 0.8 ms round trip plus 0.15 ms to run, one after another

Rows on the page

round trip 0.8 ms query 0.15 ms lists 3

  • faint tick: one trip to fetch a list
  • solid tick: one trip to fetch related rows
ApproachRound trips so farPage load time
Lazy loading97.9 ms
Batched IN5.7 ms
Dataloader3.8 ms
One join per list2.85 ms

Batched IN and the dataloader both make one extra trip for related rows; the difference is when. Batched IN makes it after each list (3 extra trips); the dataloader waits until every list has loaded and makes it once for the whole page. Lazy loading waits 34× longer than the joins for the same page.

When the server gets busy

How long a request takes as traffic rises, for three database connection pool sizes. Each line sits near 20 ms while there is headroom, then goes vertical, but how much headroom depends on the size of the pool: the pool of 2 is already at 56 ms when 80% busy, while the pool of 32 is still at 29 ms at 95%. The dashed line is a 250 ms target.

Assumes 20 ms of work per request and randomly timed arrivals

Incoming requests per second

work 20 ms pools 2 8 32 SLA 250 ms

  • one line per connection pool; the number on each wall is its size
Connection poolMax throughputBusyResponse timeStatus
2 connections100/s10%20.2 mswithin SLA
8 connections400/s3%20 mswithin SLA
32 connections1,600/s1%20 mswithin SLA

Everything holdsup.dev will show

The map of the site. Topics marked built are live on their section's page and the card takes you straight there; the rest are on the workbench. The tag on each card is the shape its curve makes, in the same colours the charts use.