How an Agent-Built Inference Engine Reduced P90 Time to First Token to About 0.5 Seconds
A public preprint experiment shows how an agent-built inference engine, tested with real multi-turn coding sessions, reached a P90 time to first token (TTFT) of about 0.48 seconds, compared with about 12 seconds for a mature general-purpose inference engine on the same hardware and model. This article explains why TTFT is distinct from generation speed, why prefix caching and scheduling dominate interactive coding workloads, and which metrics and operational controls are needed before such gains can move from an experimental setup into production.
How an Agent-Built Inference Engine Reduced P90 Time to First Token to About 0.5 Seconds
In AI-assisted coding, the most direct developer experience is often not how fast the model generates text, but how long it takes for the first token to appear after pressing Enter. Fixing a login error or asking to “move the button a little to the right” may look like just another turn in a conversation, but behind it there may be a very long context from previous turns, source-code snippets, terminal logs, and failed attempts. After the request reaches the server, the model must first process all of this input before it can emit the first token. This waiting time is time to first token, commonly called TTFT.
A recent public preprint experiment provides a useful case to examine. Under a constrained network environment and a fixed hardware budget, researchers asked an agent to build an inference serving engine responsible for receiving requests, scheduling accelerators, running the model, and returning results. They then evaluated it by replaying real coding sessions. In a specific configuration, the agent-built engine achieved a P90 TTFT of about 0.48 seconds, while a mature general-purpose inference engine took about 12 seconds under the same hardware and model conditions. Their subsequent generation speeds were very close. This gap does not mean that a self-built engine is always better than a mature solution. Rather, it shows that first-token latency bottlenecks often lie in prefill, cache hits, and scheduling policy.
1. Define the Problem: TTFT Is Not Generation Speed
TTFT consists of several stages: request queuing, batch scheduling, input prefill, first decode, and network return. Generation speed measures how many tokens per second the model can produce after it starts outputting, while TTFT measures the wait before the model “starts speaking.” The two have different optimization targets.
The experiment used P90 TTFT as the metric: after sorting all request wait times, the 90th percentile means that 90% of requests can begin replying within that time. Compared with an average, P90 is better at exposing tail latency and head-of-line blocking. For an interactive coding assistant, users perceive a major difference between “starting in half a second” and “starting in more than ten seconds.” Once the model starts replying, as long as streaming output remains stable, the experience does not break.
2. Real Session Replay: Long Context and High Prefix Reuse
The experiment replayed multi-turn real coding sessions with 16 concurrent streams and a median input of about 89,000 tokens per request. Multi-turn sessions have a key characteristic: the beginning of a new request is usually highly similar to the previous turn, with only user additions and tool outputs appended at the end. If the engine re-prefills the entire context every time, it repeatedly computes a large number of historical tokens.
Prefix caching therefore becomes central. During prefill, the model generates a key-value cache (KV Cache) for subsequent decoding. If the prefix of a new request matches a historical request, the engine can reuse the already computed KV Cache and process only the newly added part. The longer the session and the higher the prefix reuse, the more obvious the cache benefit. The logic can be illustrated as follows:
handle_request(request, cache):prefix_key = hash(request.session_id, request.prefix_tokens)if prefix_key exists in cache:kv = cache.get(prefix_key)new_tokens = request.tokens after prefixelse:kv = emptynew_tokens = request.tokensschedule_prefill(request, kv, new_tokens)schedule_decode(request)
The real difficulty is not merely “having a cache,” but whether the cache can be hit, retained, and correctly reused under concurrency. This requires coordination across session stickiness, prefix hashing, tiered caching, eviction policy, and capacity control. If requests are randomly routed to different instances, or if cache entries are evicted within a short time, the hit rate drops and prefill cost reappears.
3. Scheduling and Resource Isolation: Do Not Let Decode Hold Back Prefill
Long-context prefill is a compute-heavy task, while decode is a continuous but lighter task. If the scheduler simply mixes the two, prefill may be slowed down by a large number of decode requests, causing head-of-line blocking. For interactive workloads, common approaches include continuous batching, chunked prefill, priority scheduling, request affinity, and concurrency caps. The advantage of an agent-built engine is that it can be customized for a fixed model, fixed hardware, and a specific session pattern. A mature general-purpose engine, by contrast, must cover more models, more workloads, and more deployment forms, so its default configuration may not fit this replay scenario.
Customization also has boundaries. A self-built engine must answer: How is cache consistency guaranteed? How is isolation handled in multi-tenant environments? How is the cache invalidated after a model upgrade? Are monitoring, alerting, canary release, and failure recovery complete? Without solving these issues, low latency remains limited to the experimental environment.
4. Metrics and Load Testing: Look at P90, but Also Hit Rate and Stability
Evaluating this kind of optimization cannot rely on a single demonstration. The model and hardware should be fixed, real multi-turn traffic should be replayed, and P90/P99 TTFT, cache hit rate, prefill queue length, decode throughput, memory usage, and error rate should be recorded together. In the experimental data, the agent-built engine’s P90 TTFT was about 0.478 seconds, while the mature general-purpose engine was about 12.029 seconds. Median subsequent generation speeds were about 124.2 tokens/s and 125.0 tokens/s, respectively. This result indicates that the gap mainly occurs before the model starts speaking, not after. However, it represents only a specific workload and configuration and cannot be directly generalized into a universal conclusion.
5. Engineering Lessons: Making “Half-Second Opening” an Operable Capability
For developers, the reusable conclusion is this: to optimize first-token latency, prioritize analysis of session prefix reuse rate, cache residency policy, and prefill scheduling, rather than focusing only on decode throughput. For platforms, prefix caching, request affinity, resource isolation, observability, and load-test replay need to become standard capabilities, with a balance between generality and scenario-specific customization. The agent-built inference engine demonstrates the potential of “customizing for the workload,” but production deployment still requires a safe, stable, maintainable, and verifiable engineering system. A half-second opening is not a single trick; it is the combined result of caching, scheduling, and metric governance.
