← Back to concept explainers

Concept Fable

Prefill

Conclusion first:Prefill is the stage in LLM inference where the input prompt/context is processed and the initial KV cache is built. It happens before the model generates the first token, and its compute usually grows with input length. Understanding prefill helps analyze TTFT, long-context cost, prefix/prompt caching, chunked prefill, batching, and inference serving capacity planning.

Prefill · LLM inference

Read the story first. There is no rush to give a definition here; let the question grow on its own first.

Fable

Before the storyteller speaks, he spreads the entire old case file across the table

There was a storyteller in the teahouse who could keep going as soon as a guest asked a question. For short stories, he spoke almost immediately, as if he already knew the answer.

Later a guest brought a thick stack of old cases and asked the storyteller to read them all before judging. The storyteller took a long time to speak, and the tea drinkers thought he had slowed down.

The shopkeeper urged him to explain while reading. As a result, the first half was lively, but only in the second half did he discover that the key clue was at the end of the scroll, and all the earlier judgments had to be overturned.

The storyteller explained that before speaking, one must first read the old case into memory and sort out the characters, timeline, and clues. Only then, when each word is uttered later, is there no need to flip through the entire scroll again.

The shopkeeper then split the waiting into two accounting stages: first reading the scroll, then telling the story. The reading stage depended on the length of the old case; the storytelling stage spat out one word at a time.

The teahouse also learned to prepare commonly used old cases in advance. Frequently asked cases are laid out first, so when guests arrive they can move into the storytelling stage more quickly.

Later, everyone no longer lumped all latency together. Where long context is slow, where caching can save, and where concurrency will jam—all became clear.

The storyteller said that a slow answer is not necessarily slow in generating the answer; sometimes it is slow in the complete context digestion before the first sentence. Later, an even more troublesome job came. On the surface it was just an old problem magnified, but in reality it forced out all the gaps hidden in the process: who takes over first, who can make changes, and how to return to the previous step after an error. Places that used to get by on familiarity and tacit understanding now all had to be made clear. The person in charge did not urge everyone to be more careful again, but walked through the site once more. He had people record every handoff, every failure, and every remediation, which places were merely slow, which places would harm the result, and which places would be hard to trace back once wrong. After the new rules were rolled out, the first few days were not smooth. Some complained about an extra check, and some felt their old experience was being offended. But when the next anomaly appeared, for the first time everyone could follow the traces to find where the problem occurred, instead of gathering around the result and guessing at each other. This approach did not make the site magical; it simply made responsibility, boundaries, and the way back clear. What could be automated continued to be automated, places requiring human judgment stopped for confirmation, and truly dangerous actions were no longer released together with ordinary actions.

Reveal

This story is about: prefilling

Prefill is the stage in LLM inference where the input prompt/context is processed and the initial KV cache is built. It happens before the model generates the first token, and its compute usually grows with input length. Understanding prefill helps analyze TTFT, long-context cost, prefix/prompt caching, chunked prefill, batching, and inference serving capacity planning.

What matters is that it is not just a term, but a structural problem that repeatedly appears in real AI / Agent systems. Understanding it lets you judge when to add a model, when to change a process, and when to add governance.

Metaphor mapping

  • A thick stack of old cases: the input prompt and context
  • Read the scroll before speaking: the Prefill stage
  • Emits a single word: the Decode stage
  • First-half misstatement: the risk of generating before processing the full context
  • Account in two segments: distinguish prefill latency from decode latency
  • Lay out commonly used old cases first: prefix/prompt caching
  • Long context is slow: prefill computation grows with input length
  • Before the first sentence: an important component of TTFT

Andy Ren Xu's judgment

The practical value of this concept is that it helps you break "AI features that look smart" into deliverable, verifiable, and governable units of work.

decodeKV cache

Related distinctions

This concept is easily confused with adjacent concepts; it is recommended to continue to the comparison page.

京ICP备2026014272号