Chapter 15: Performance and cost

A profile tells you what is slow today. Big O tells you what will get slow next year, when there is more data.

Big O

Also called Time complexity, O(n)

A way of saying how a program's work grows as its input grows. With O(n), twice the data takes about twice as long. With O(n²), twice the data takes about four times as long. It says nothing about how long any one run takes.

An agent's tests run on ten rows, and at ten rows everything is instant. A loop inside a loop can pass every check and only hurt a year later, when the table has grown. It is also a claim agents love to make, so ask to see it measured at two or three sizes.

Say it to your agent

“dedupe in src/report.ts has a loop inside a loop. Time it at 1,000, 10,000 and 100,000 rows and show me the three numbers. If ten times the rows takes about a hundred times as long, replace the inner search with a Set and rerun the same three sizes.”

The workshop

Name a word, or describe what you mean in everyday language.