Cutting Time to First Token from 12 Seconds to Half a Second: An Engineering Deep Dive
Time to First Token (TTFT) is often the metric that defines how responsive an AI application feels to users. This article walks through a real-world test where two inference engines running identical hardware and model weights showed a dramatic gap: one delivered a P90 TTFT of around 12 seconds, the other just 0.48 seconds — with nearly identical generation throughput. We break down why prefill dominates perceived latency, how prefix caching and KV Cache reuse eliminate redundant computation, and what trade-offs around memory planning, workload patterns, and accuracy you need to manage. Practical recommendations are included for teams optimizing their own inference services.
It Starts with “Waiting for a Response”
In interactive AI applications, the wait after a user hits Enter often determines their judgment of the overall experience. In engineering terms, this has a precise measurement: Time to First Token (TTFT) — the time from when a request is sent to when the model begins returning its first character.
A recent test illustrated the optimization headroom for this metric very concretely: on the same server hardware, with the same model weights, two inference engines were replayed against the same batch of real coding sessions. One produced a P90 first-token latency of about 12 seconds; the other, just 0.48 seconds. In other words, the first setup made users wait a full twelve seconds before seeing the first word, while the second started streaming a response almost the moment Enter was pressed.
And once generation began, their throughput was nearly identical: by the median, the two engines each produced roughly 124 and 125 tokens per second — a negligible difference in generation speed. This means the entire gap was concentrated in the moment “before speaking” — the phase where the model processes the input and prepares its response. In inference system terminology, this phase is called prefill.
Prefill: The Invisible Time Before the Response
To understand the cost of prefill, you first need to see what happens in a complete inference request.
Suppose you’re using an AI coding assistant to work on a web page. You’ve already pasted source code, pasted error messages, and tried several rounds of suggested fixes. On this round, you only add one sentence: “Move the login button slightly to the right.”
But what the server receives is far more than that sentence. The previous rounds of conversation — including the complete file contents you pasted, the code blocks from every revision, and even the output returned by certain tools — are all sent to the model as context. In the 16-way concurrent coding sessions replayed in the test, the median single input reached 89,000 tokens. That scale is comparable to the full text of a medium-to-long technical document.
The model must read all 89,000 tokens before it can “understand” what your last sentence is actually asking for. That reading-and-computing process is the prefill. Only after prefill completes does the model enter the phase of generating the response token by token, known as decode. Nearly all user-perceived latency is consumed by prefill.
If you think of an inference request as an exam: prefill is like a candidate reading through the entire exam paper and all reference materials before starting to answer, while decode is the answering process itself. The reading time often far exceeds the answering time.
Cache Hits: Skipping What Has Already Been Read
A natural optimization idea follows: if the exam content is nearly identical to last time, can we only read the new part?
This is exactly the core idea behind prefix caching. If the beginning of a new request — i.e., the earlier rounds of conversation — is the same as the previous round, the engine can reuse previously computed results and only incrementally process the newly appended content.
The key is understanding what the “previously computed results” actually are. In the Transformer architecture, when a model reads a piece of text, it leaves behind an intermediate computational record called the KV Cache (key-value cache). It is essentially a compressed representation of the tokens already processed, capturing the model’s “understanding state” after reading that content. With this cache, the next time the same prefix appears, the engine doesn’t need to recompute everything — it simply pulls the cache and continues processing the new content.
This explains why the latency gap between the two engines was so large: the mature solution had prefix caching enabled by default, but it failed to deliver in this test; while the engine built by Claude precisely reused all the cached context from previous rounds when only a single prompt line changed, processing only the few dozen newly added tokens. One engine was performing a full prefill over 89,000 tokens; the other, an incremental prefill over just a few dozen tokens. The difference naturally scales by orders of magnitude.
There’s a subtle but important detail here: prefix caching is not simple “string matching.” Its granularity is token-level, and it only hits when the prefix tokens of two sequences are exactly identical. Any tiny variation — even an extra space or a line break — invalidates the cache and forces the engine to recompute from scratch. In multi-turn coding sessions, where “several consecutive rounds are highly related and only the last sentence is new” happens to be the ideal hit pattern for prefix caching, this optimization shines.
Engineering Trade-offs, Seen Through One Test
If we abstract this test into a general question: for an inference service where request inputs routinely approach 100,000 tokens across many concurrent sessions, how do you keep P90 first-token latency under one second?
The answer is not a single word — “enable caching.” Several dimensions must be considered together.
Cache Hit Rate Is Strongly Tied to Workload Characteristics
The effectiveness of prefix caching depends heavily on actual traffic patterns. If every request carries a completely different context — say, users paste different files each time — prefix overlap is low, the hit rate stays low, and the benefit of this optimization shrinks dramatically. So when evaluating inference engines, don’t rely on benchmark tests alone; measure hit rates and latency distributions using replays of your own real requests.
Trading Memory for Latency: Capacity Planning for Caches
The KV Cache consumes GPU memory. With a fixed total across four GPUs, the more memory the cache takes, the less remains for actual computation. It gets more complicated: concurrent requests compete for the same pool of memory. The fact that P90 latency (not the median) dropped so significantly indicates that the engine preserved first-token latency even under extreme queuing — which usually means finer-grained control over memory management and scheduling, such as cache eviction policies, long-lived connection handling, and request scheduling priorities. These underlying mechanisms are more complex than “whether to cache,” and they ultimately determine the ceiling.
Accuracy Cannot Be Sacrificed for Speed
One point must be emphasized: prefix caching does not change the model’s output. Mathematically, reusing the KV Cache produces results equivalent to a full recomputed prefill — it merely skips redundant computation rather than approximating it. So optimization paths centered on cache reuse are safe with respect to output quality. But if you introduce other techniques into the inference pipeline — such as speculative decoding or early termination — those require separate accuracy evaluations.
Practical Recommendations for Engineering Teams
Returning to the developer’s perspective, if you want to optimize first-token latency in your own inference service, several steps can be applied directly.
First, establish percentile-based latency monitoring. Average latency alone is far from sufficient. P90 or even P99 reflects the real user experience, because queuing, cache misses, and network jitter tend to stretch the tail latency of the “unlucky” requests.
Second, test with replays of real requests, not official standard benchmarks. Differences between inference engines get amplified under specific workload shapes. A platform dominated by coding tasks and a service dominated by short Q&A may have completely different requirements. Only your own data can reveal which solution fits best.
Third, understand your request structure. If your business involves lots of long context, multi-turn conversations, and users making only small edits each time, you are naturally a prime beneficiary of prefix caching. Try to keep these session contexts as stable and continuous as possible, minimizing unnecessary disruptions in between, to raise cache hit rates.
Fourth, consider decoupling prefill from decode. In larger-scale services, prefill and decode can be split onto separate compute resources, preventing long-context prefill from blocking token streams that are actively generating. This is a deeper architectural optimization, but for scenarios chasing extreme latency, it’s worth evaluating.
Closing Thoughts
First-token latency may seem like just one metric among many, but it directly determines the sense of “interactivity” — whether users feel they are conversing with a system or submitting a job to a queue. The gap between twelve seconds and half a second is, at its core, the dividing line between a “batch processing” experience and a “conversation” experience.
The significance of this test lies not in the verdict on any specific engine, but in demonstrating a quantifiable optimization opportunity: on identical hardware, with proper cache reuse and scheduling strategies, first-token latency can be compressed by more than an order of magnitude. For anyone building inference services, this is a direction worth taking seriously — start with P90 monitoring, dig into prefill bottlenecks, then refine caching and scheduling. Every step you take shaves a bit more off the wait. And every millisecond saved moves you closer to turning “the machine is computing” into “a partner is answering.”
