Why Does the First LLM Token Take Longer? A developer published a walkthrough explaining why long-context chats take longer to produce their first output token, attributing the delay to prefill work that scales with prompt length while decode proceeds one token at a time. The post provides illustrative timings showing a long chat starting 200 ms later than a fresh one, and offers a Python helper that measures time to first text and average inter-chunk gap from streaming events, warning that timers stopping at the first event can mask the difference. Open a fresh chat and type Finish this sentence: A triangle has… . Now ask the same thing at the end of a long conversation. Both replies might say three sides. But the second can take longer to start. The sentence you typed stayed the same. The prompt the app sent to the model got longer. In the first post https://dev.to/int8ai/what-happens-after-you-hit-send-an-illustrated-llm-walkthrough-4mgb , we followed the loop that chooses a token, appends it, and repeats. This time, let’s see what happens before that first choice. Think of joining a conversation halfway through. If someone asks “What about that one?”, you need to hear some of what came before. A chat app gives the model that context by including earlier turns in the prompt. Fresh: Instructions Latest message Long: Instructions History Latest message Processing the prompt is called prefill . Since the prompt tokens are already available, the GPU can work on many positions in parallel. A longer prompt still creates more work. It has more token positions to process, and with standard attention, later positions can compare against more earlier ones. Prefill produces the scores used to choose the first output token . Then decode generates what follows. To score the token after " three" , the model first needs to know whether it picked " three" or " four" . That dependency gives ordinary generation its one-token-at-a-time rhythm. Imagine two requests to the same model. We’ll keep setup and delivery time fixed and change only prefill. These timings are illustrative. | Before the first text chunk | Fresh chat | Long chat | |---|---|---| | Setup, queueing, and tokenization | 40 ms | 40 ms | | Prefill | 60 ms | 260 ms | | First-token selection and delivery | 20 ms | 20 ms | | Time to first text | 120 ms | 320 ms | Now suppose both replies stream the same three text chunks. php Fresh: 120 ms - 145 ms - 170 ms Long: 320 ms - 345 ms - 370 ms The long chat starts 200 ms later . Once text appears, both replies advance at 25 ms per chunk in this example. In production, a longer context can also affect decode because each new token may attend to more earlier positions. Time to first token TTFT measures the wait for the first output token. Inter-token latency ITL measures the gap between consecutive output tokens. Check where your dashboard starts the clock. A client-side measurement can include network time as well as time spent on the server. NVIDIA inference metrics https://docs.nvidia.com/nim/benchmarking/llm/1.0.0/metrics Now imagine both requests receive an event with no text at 40 ms . A timer that stops at the first event reports 40 ms for both requests and misses the entire 200 ms difference. If you only have text chunks, measure time to first text and inter-chunk latency . A chunk can contain multiple tokens. Here, each event is a pair of elapsed milliseconds and text. An empty string represents an event with no text. python def stream times events : text times = ms for ms, text in events if text if not text times: raise ValueError "No text chunks arrived" first = text times 0 last = text times -1 gaps = len text times - 1 return { "first text ms": first, "avg chunk gap ms": last - first / gaps if gaps else None, "last text ms": last, } fresh = 40, "" , 120, " three" , 145, " sides" , 170, "." long = 40, "" , 320, " three" , 345, " sides" , 370, "." assert fresh 0 0 == long 0 0 == 40 assert stream times fresh == { "first text ms": 120, "avg chunk gap ms": 25.0, "last text ms": 170, } assert stream times long == { "first text ms": 320, "avg chunk gap ms": 25.0, "last text ms": 370, } print "Fresh chat", stream times fresh print "Long chat ", stream times long Try it. Change the last two timestamps in long to 365 and 410 . Update the expected values in the second assertion and run it again. First text still arrives at 320 ms. The average gap rises from 25 ms to 45 ms. A dashboard that tracks only first text will miss that slowdown. Some serving engines can shorten prefill by reusing work when a request starts with the same sequence of tokens as an earlier request. That’s prefix caching . In the next post, we’ll look at what the KV cache actually stores and how decode uses it. vLLM prefix caching https://docs.vllm.ai/en/stable/features/automatic prefix caching/ When you’ve seen a slow streamed reply, was the delay before the first text or between chunks? Adapted from Prefill: Process the Prompt and Build the Cache https://int8ai.com/llm-foundations/prefill-process-the-prompt , which includes a causal attention diagram, a worked GPU compute estimate, and a KV cache sizing exercise. AI assisted with drafting this adaptation.