High-Speed LLM Inference: Engineering Practices and Performance Analysis
This article examines why output speed has become the primary bottleneck in interactive LLM applications, breaking down the two distinct metrics that define perceived latency: time to first token (TTFT) and decode throughput. It challenges the assumption that faster inference requires smaller models, outlining four optimization paths that are largely independent of parameter count: memory-access optimization during decoding, continuous batching, speculative decoding, and prefix caching. A vendor-neutral reference architecture is presented, along with the metrics needed to validate performance (including goodput and tail latency), a regression checklist to ensure capability is not traded for speed, and practical guidance on rollout order and common pitfalls.
1. The Problem: Why Output Speed Became the Experience Bottleneck
In interactive generation scenarios, the “slowness” users perceive actually comes from two completely different sources of latency. The first is time to first token (TTFT): the interval between sending a request and receiving the first output unit. The second is decode throughput: the rate at which the model continues to emit content, typically measured in tokens per second.
A human blink takes roughly 0.3 seconds. If a service can output about 400 tokens per second, a single blink is enough time to generate more than a hundred tokens—approaching the range where reading speed can no longer keep up with generation speed. The experience gap described in the source material comes from exactly this: on the same task, a high-throughput version delivered a complete page with navigation, card lists, and a data panel within one minute, while the standard version took several times longer, leaving the user watching a blinking cursor for the first half of the wait.
It is important to stress that these two metrics are governed by different bottlenecks and cannot be summarized by a single number:
- TTFT is mainly affected by queue wait time, prompt length, batching strategy, and cold starts.
- Decode throughput is mainly affected by GPU memory bandwidth, in-batch concurrency, attention implementation, and sampling strategy.
2. Breaking an Assumption: Fast Does Not Mean Small
For a while, the industry settled into an almost default correspondence: if you want speed, pick a model with a lightweight parameter count; if you want capability, accept slower responses. This tradeoff did hold early on, because lightweight models read fewer weights and consume less bandwidth per decode step.
From an engineering perspective, however, the real source of speed is not “fewer parameters” but “more sensible organization of effective computation per unit of time.” Breaking that down yields four optimization paths that are independent of, or only weakly related to, parameter count:
- Memory-access optimization in the decode phase. Every step of autoregressive decoding reads weights and a growing context cache, so the bottleneck is usually memory bandwidth rather than compute. More efficient attention cache management, operator fusion, and better-suited numerical precision can substantially raise effective throughput per GPU.
- Continuous batching and dynamic scheduling. Traditional static batching requires all requests in a batch to start and finish together, so short requests must wait for long ones. Continuous batching lets requests enter and leave the batch freely after each step, filling idle compute.
- Speculative decoding. A lighter draft generation path guesses several tokens first, then the main model verifies them in a single pass; accepted tokens are adopted directly, rejected ones are rolled back. It does not change the output distribution, only how many tokens are produced per step.
- Prefix cache reuse. Stable prefixes such as system prompts, coding conventions, and project context can be cached, so subsequent requests that hit the cache skip repeated computation and TTFT drops accordingly.
Only when these four paths stack together can you get the result of “flagship-level capability running at extremely high output speed.” The capability results mentioned in the source material (ranking near the top on general front-end code generation benchmarks) and the speed metrics (hundreds of tokens per second, TTFT held under one second, several times faster than a standard configuration) should be understood as the joint product of these two optimization lines, not a single-point trick.
3. Reference Architecture: Building a Low-Latency, High-Throughput Inference Service
Below is a vendor-neutral general architecture that maps directly onto common product categories on Baidu AI Cloud.
- Ingress layer: use a load balancer to handle external traffic, with connection reuse and request coalescing to avoid the extra latency of frequent handshakes.
- Inference layer: run the inference runtime on a container platform, scaling horizontally according to memory and concurrency capacity; enable continuous batching, prefix caching, and speculative decoding.
- Cache layer: use object storage for model weights and template resources, paired with a local high-speed cache to reduce weight pull time during cold starts.
- Async pipeline: route long-running tasks (batch code generation, document parsing) through a message queue for peak shaving, isolated from online interactive traffic so the two do not compete for resources.
- Observability: collect TTFT, decode throughput, in-batch concurrency, memory usage, and rejection rate through logging and monitoring/alerting services to form a basis for capacity planning.
The key design principle is “separating fast from slow”: interactive requests go through a high-priority queue with a capped maximum output length, while offline batch processing goes through a low-priority queue. When the two run mixed, long-output requests occupy batch slots for extended periods, and the TTFT of interactive requests degrades rapidly.
4. Turning Speed into Verifiable Metrics
No measurement, no optimization. At minimum, collect the following four categories of data:
# Metric definitions (pseudocode)ttft_ms = first_token_time - request_start_timedecode_tok_s = (output_tokens - 1) / (last_token_time - first_token_time)goodput = count of requests where (ttft_ms < SLO and decode_tok_s > threshold)slot_occupancy = active sequences in batch / max concurrency slots
When load testing, avoid reporting only averages. Latency distributions for generation workloads typically have pronounced long tails, so observe P50/P95/P99 simultaneously and bucket statistics by input length and output length. A common mistake is load testing with extremely short outputs: TTFT gets amortized, throughput numbers look inflated, and the real online experience is poor.
5. Capability Cannot Be Compromised: Verifying “Flagship-Level” Is Still Online
After speeding up, you must run a capability regression; otherwise you are trading quality for speed. An executable verification checklist includes:
- Functional correctness: given the same set of page generation, API integration, and script refactoring tasks, compare the runnable rate and human scores before and after the speedup.
- Long-context consistency: under longer contexts, check instruction following and structural integrity to confirm that caching and batching have not introduced cross-contamination.
- Sampling stability: fix the random seed for repeated experiments and observe whether output variance expands abnormally.
- Distribution consistency: if speculative decoding is used, confirm via statistical testing that the output distribution has not changed.
Skeleton of a sample regression script:
cases = load_cases("task_set.jsonl")for c in cases:out_fast = call_api(c.prompt, config=FAST)out_base = call_api(c.prompt, config=BASE)record(c.id, ttft=out_fast.ttft, tok_s=out_fast.tok_s,pass_rate=judge(out_fast.text, c.golden),base_pass=judge(out_base.text, c.golden))report(percentiles=[50, 95, 99])
6. Rollout Advice and Common Pitfalls
- Do prefix caching first, then speculative decoding. The former has low rework cost and direct payoff, and is especially suited to coding assistant scenarios with long system prompts.
- Cap output length. Without a length limit, individual requests occupy slots for a long time and drag down overall TTFT.
- Treat cold starts separately. The cost of scaling to zero and back up is far higher than keeping a minimum resident instance, so interactive workloads should retain warm replicas.
- Do not make capacity decisions on a single average metric. Use goodput (effective throughput meeting SLOs) as the scaling trigger.
- Evaluate cost across the full pipeline. Beyond inference compute, account for cache, logging, and monitoring overhead.
7. Summary
High output speed and flagship-level capability are not mutually exclusive. The real dividing line is whether you systematically organize the memory-access bottleneck in the decode phase, batch scheduling, prefix reuse, and speculative verification, and quantify the effect with TTFT, decode throughput, and goodput. For developers, the path is clear: build an inference service on top of general container, cache, messaging, and monitoring capabilities; first separate fast and slow traffic and add prefix caching; then gradually introduce speculative decoding and capacity governance; and finally hold the quality line with capability regression and tail-latency analysis.
