cd /news/large-language-models/why-does-the-first-llm-token-take-lo… · home › topics › large-language-models › article
[ARTICLE · art-177229] src=dev.to ↗ pub= topic=large-language-models verified=true sentiment=· neutral

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.

recommendation

When tracking LLM latency, filter streaming events to non-empty text chunks and compute time to first text plus average chunk gap, since timers that stop at the first event can hide prefill delays.

more in playbook: Running AI in production
by read4 min views5 publishedNov 27, 2026

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, 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.

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

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.

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

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, which includes a causal attention diagram, a worked GPU compute estimate, and a KV cache sizing exercise. AI assisted with drafting this adaptation.

── more in #large-language-models 4 stories · sorted by recency
── more on @nvidia 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/why-does-the-first-l…] indexed:0 read:4min 2026-11-27 · —