Agent-Built Inference Engine Slashes P90 Time to First Token from 12 Seconds to Under 0.5 Seconds
A recent preprint from a joint university–chip vendor research team describes the Singularity Benchmark, in which an AI agent built a complete inference engine for a specific GPU in 12 hours without internet access. In a replay of 16 concurrent coding sessions with long contexts, the agent-built engine reached a P90 time to first token (TTFT) of 0.48 seconds, compared with 12.029 seconds for the mature open-source SGLang engine on the same hardware. Decode throughput was nearly identical—124.2 vs. 125.0 tokens/s—showing that the gap came almost entirely from prefill. The article explains prefill and decode, KV cache and prefix caching, likely scheduling and cache-management overheads in general-purpose engines, the caveats of scenario-specific optimization, and practical takeaways for inference engineering.
From Waiting for a Reply to Near-Instant Response
When developers use AI-assisted programming, a familiar scene repeats: they finish editing code, paste a new error log into the chat box, press Enter, and then wait. The cursor blinks, the terminal does nothing, and the first character appears only after a tense count of seconds.
This waiting period is known as time to first token (TTFT). It measures the interval between a client sending a request and the model beginning to generate a response. Unlike tokens-per-second, which measures generation speed, TTFT is the most direct signal users have about system responsiveness. Even if a system generates tokens at lightning speed, a TTFT of more than ten seconds still fragments the experience.
A recent preprint from a joint university–chip vendor research team reports a striking result. In a simulated real-world coding session, an inference engine written by an AI agent achieved a P90 TTFT of only 0.48 seconds. A mature open-source inference engine, under the same hardware conditions, reached 12.029 seconds on the same metric. Although the two engines had nearly identical generation speed after the response began—124.2 tokens/s vs. 125.0 tokens/s—the 11.5-second gap before the first token created a radically different interactive experience.
An Extreme Engineering Test: AI Builds Its Own Engine
The study, called the Singularity Benchmark, essentially asks a forward-looking question: can an agent build an agent? More specifically, the researchers gave an AI agent a demanding task: without internet access and with only basic server code, use a set of intelligent programming tools to write a complete inference engine for a specific GPU model within 12 hours.
The engine had to provide full inference service functions: receive service requests from external users, schedule those requests onto GPU resources to run a large model, and stream generated text tokens back to the client. This process involves HTTP service setup, GPU memory management, KV cache management, continuous batching, token sampling strategies, and a range of other complex systems engineering problems.
The researchers did not evaluate the agent-built engine through static code review alone. They ran a live test. They used four high-end data-center GPUs (GB300-class) to run the same model and replayed a set of 16 concurrent session logs from real coding scenarios. All 16 requests hit the engine at the same moment, and each contained the full context of several previous coding turns, with a median input length of 89,000 tokens. Under this combined pressure of high concurrency and large context, the 90th-percentile user wait time produced the stark result above.
The Prefill Bottleneck: Why Thinking Takes Longer Than Speaking
To understand the 11.5-second gap, it is necessary to separate the two core stages of large-model inference: prefill and decode.
In the prefill stage, the system feeds thousands or even tens of thousands of input tokens into the model at once and computes the key-value pairs for each token in parallel. These pairs form the Key-Value Cache (KV Cache), an intermediate product in the Transformer architecture that stores historical attention information and determines whether the model can remember prior context. The duration of prefill is directly correlated with the number of input tokens: the longer the input, the greater the computation.
In the decode stage, the model generates new tokens one at a time until it encounters a stop token. Decode speed is usually measured in tokens per second. The two engines performed similarly here, indicating that their per-sample sampling and computation performance were at the same level.
TTFT is therefore almost entirely consumed by prefill. In the replayed coding sessions, the problem is especially severe: every new conversational turn carries the entire chat history, often tens of thousands of tokens. That means the engine must first compute the full 89,000-token context before answering even a simple instruction such as “move the login button a little to the right.”
If every interaction required a full recomputation of the historical context, GPU compute resources would be wasted on a massive scale, and user wait times would be unacceptable. This leads to the key solution: prefix caching.
The Key to Lower Latency: Cache Hits or Reinventing the Wheel?
Real user behavior reveals a strong temporal pattern in multi-turn conversations: the beginning of a new request is almost always identical to the previous request, because the earlier chat history is sent to the server again unchanged. If the beginning of the input has not changed, the KV Cache computed for that segment should theoretically be the same.
Prefix caching builds on this idea. The engine reserves an area in server memory or GPU memory and stores previously computed input segments and their corresponding KV Cache. When a new request arrives, the engine first checks whether the prefix of the input text matches a segment in the cache. If it does, the engine reuses the cached KV Cache, computes only the newly added text, and then concatenates the “old cache” with the “new computation” before sending the result to decode.
The mature open-source inference engine SGLang also has a prefix caching mechanism, and its scheduling design has long been well regarded. Why, then, did SGLang still require more than 12 seconds of TTFT in the test?
The authors speculate on several reasons:
- Cache hit rate and scheduling overhead: With 16 concurrent requests, each request has a different history length. A mature engine must calculate text hashes for exact matching when using the cache. Under extreme concurrency, lock contention, hash computation, and cache-block management overhead may grow sharply.
- Locking and mutual exclusion for long sequences: When the prefixes of multiple concurrent requests overlap or intersect in physical address space, the memory allocator must handle them carefully. If the engine uses strict mutual exclusion locks for KV Cache partitions, long-sequence reads can cause serious resource waiting.
- Request-level context stitching: Mature general-purpose engines often have multiple internal data-flow layers to support various deep learning model structures. Along the path from cache blocks to the inference compute core, excessive memory copying may occur.
By contrast, the agent-built engine had no historical baggage and was tailored to this specific task with custom data structures and a custom scheduler. It may have used a minimal hashing strategy that reduced the cost of “computing the prefix hash” and “looking up the table” to microseconds. It also optimized GPU memory layout so that the channel between cache blocks and compute stream processors was seamless, achieving a cache hit rate of about 99.6%—meaning that a very large share of historical tokens did not need to be recomputed. This stripped-down code, designed only to solve the immediate problem, produced remarkable efficiency in this specific scenario.
Engineering Validation and Lessons Beyond the Benchmark
The result is encouraging, but it also calls for a measured technical view:
- Scenario specificity: The AI-written engine was highly customized under known hardware, a known model architecture, and a known concurrency level. It did not need to support different GPU brands or multiple model versions, so it could remove a large amount of general-purpose code. SGLang, as a general solution, must manage hardware adaptation logic for many environments, and its performance under more demanding general workloads remains relevant.
- Cost and stability: Generating this custom engine consumed 12 hours of AI agent runtime on high-end GPUs. For most small and medium-sized organizations without a low-level compute optimization team, using a general inference framework remains the best choice for cost-effectiveness and stability.
- Future direction: The greatest value of this test is that it validates the feasibility of “AI autonomously building low-level infrastructure.” When an agent can clearly understand highly complex computer systems concepts such as distributed scheduling and GPU memory management and independently produce runnable engineering code, it signals a new stage of “AI-assisted AI framework R&D.” In future cloud-native development environments, intelligent assistants may no longer only write business logic; they may also generate higher-performance adaptation layers on demand, greatly shortening the time needed to launch on a specific hardware platform.
Every quantitative result in this test—whether 0.478 seconds or 12.029 seconds—is only a snapshot under specific hardware, a specific model, and a specific concurrency pattern. It does not prove that SGLang is inferior in absolute performance to a temporary engine written by AI, but it does demonstrate that a reasonable caching strategy can have a disruptive impact on user experience.
For inference engine engineering, this “AI vs. established framework” comparison offers several general lessons:
- Prioritize prefill optimization: With fixed hardware compute, saving compute resources through software-defined caching—such as introducing finer-grained KV Cache management units like paged attention—is often more effective than simply adding hardware.
- Exploit request characteristics: For repeated prefixes that appear frequently in real workloads, such as system prompts and chat history, design dedicated hash lookup algorithms that reduce lookup latency to the nanosecond level.
- Watch scheduling overhead: The higher the concurrency, the more likely the scheduler’s own CPU usage becomes a bottleneck. The 16-way concurrency data in the test already hints at this. Future inference engines need to reduce CPU-side memory copying to zero.
In summary, this experiment in which “AI writes its own inference engine” is not only a performance comparison but also an early preview of a new model for human R&D. When AI is no longer treated merely as a tool for writing CRUD scripts but as an “engineer” capable of designing system architectures and optimizing low-level scheduling strategies, the boundaries of software development will expand once again.
