productinterview.tools
MenuClose

Prefill and Decode: Where LLM Latency Comes From

The two phases of generating a response: prefill reads the whole prompt (setting time to first token); decode writes output one token at a time.

1 min read
On this page
  1. How it works
  2. The numbers
  3. Why it matters, by role
  4. How interviews test it
  5. Common confusions
  6. Related concepts
  7. Sources

How it works

  • Prefill processes all input tokens together.
  • Decode generates each token by reading the model's weights, limited mostly by memory bandwidth.

Full lesson: AI numbers: serving, cost and latency.

The numbers

  • Total time ≈ time to first token + output tokens × time per token.

Why it matters, by role

  • AI Infrastructure PMProduct Manager. Decides what a product should do, for whom, and why. Read the full explanation: Latency targets.
  • AI Product Engineer: Streaming and context trimming.
  • Applied AI PM: Perceived speed.

How interviews test it

Common confusions

  • Streaming doesn't shorten total time; it shortens the wait before anything appears.
  • Long outputs slow things more than long inputs, per token.

Sources