LLM Inference Performance Optimization: A Practical Guide for Engineering Teams

    This article breaks down large language model inference performance into measurable metrics and explains how engineering teams can measure, locate, and optimize bottlenecks. It covers TTFT, output throughput, thinking and answer phase rates, P50 and tail latency, along with four proven optimization techniques: KV cache management, continuous batching, speculative decoding, and quantization with compilation. It also addresses differentiated scheduling for reasoning and answer phases, structured evaluation of coding ability, and building an inference foundation with general-purpose cloud capabilities. Readers will gain a reproducible framework for making long-term, comparable model selection decisions.

    1. Introduction: From the Parameter Race to the Inference Efficiency Race

    Over the past two years, the focus of the large model industry has shifted noticeably. Early competition centered on parameter count and training data volume, then moved to side-by-side evaluations of general and coding capabilities. Today, what truly determines user experience and unit cost is efficiency during the inference stage. Even a model in the top tier of general evaluations will struggle to scale in real business scenarios if it has high time-to-first-token, low throughput, or noticeable jitter under long contexts.

    A recent side-by-side comparison in a technical community sparked considerable discussion. A newly released model was placed alongside two mainstream “lightweight, fast models.” It landed between the two in general capability, entering the top tier of mainstream domestic models. In programming tasks it ranked in the middle overall but overtook the others on individual items, performing best on 3D solar system visualization applications and tying with another model on 3D growing tree tasks. For inference speed, its turbo mode reached a peak of roughly 2100 tokens/s, with the thinking and answer phases at approximately 984 and 1816 tokens/s respectively, and a median response time of about 3.1 seconds.

    This article does not restate the evaluation conclusions of any specific product. Instead, it abstracts such phenomena into a general engineering problem: which stages determine LLM inference performance, and how should engineering teams measure, locate, and optimize it? When cloud-side capabilities are involved, only general product categories are used.

    2. Breaking “Inference Speed” into Measurable Metrics

    Many teams lack a shared vocabulary when discussing whether a model is “fast,” because they have not broken speed down into observable, attributable metrics. A commonly accepted set of baseline metrics includes:

    • Time to first token (TTFT): The time from request dispatch to receiving the first output token, which determines the perceived responsiveness of “does it react when I click.”
    • Output throughput (tokens/s): The number of tokens generated per unit of time, usually distinguished between peak and median.
    • Thinking phase rate and answer phase rate: Models with an explicit reasoning process first produce internal thinking content and then the formal answer, and the two phases often differ in speed.
    • Median response time (P50) and tail latency (P95/P99): Averages hide the long tail; only the median plus tail percentiles can support capacity planning.
    • Cost per request: Strongly correlated with throughput, memory footprint, and batching strategy.

    It is important to emphasize that peak throughput is “the upper bound under ideal conditions,” while median response time is “the real experience of most users.” Publishing only peak numbers in evaluations tends to overestimate actual service capacity. Teams are advised to report peak, P50, and P95 together in load test reports, along with concurrency, input/output length distribution, and whether caching is enabled.

    The metric collection logic can be expressed as the following pseudocode:

    1. # Collect key latency metrics for a single request
    2. def measure(request, model_client):
    3. t0 = now()
    4. first_token_at = None
    5. thinking_tokens = 0
    6. answer_tokens = 0
    7. for chunk in model_client.stream(request):
    8. if first_token_at is None:
    9. first_token_at = now()
    10. ttft = first_token_at - t0
    11. if chunk.phase == "thinking":
    12. thinking_tokens += 1
    13. else:
    14. answer_tokens += 1
    15. total = now() - t0
    16. return {
    17. "ttft_ms": ttft * 1000,
    18. "thinking_tps": thinking_tokens / (total - ttft),
    19. "answer_tps": answer_tokens / (total - ttft),
    20. "total_ms": total * 1000,
    21. }

    3. Four General Optimization Techniques Behind “Turbo Mode”

    The so-called “turbo mode” is not a single switch but a combination of several engineering techniques. The following four have been widely validated in the industry:

    1. Memory and KV Cache Management

    Autoregressive decoding reads the historical key-value cache for every generated token, so memory bandwidth often becomes a bottleneck before compute does. Common approaches include paged cache management, prefix cache reuse, and cache compression and quantization for long contexts. Prefix caching is especially beneficial for customer service and coding assistant scenarios where “the system prompt is fixed and user input varies.”

    2. Continuous Batching and Request Scheduling

    Static batching makes short requests wait for long ones, causing head-of-line blocking. Continuous batching dynamically assembles batches at the token level, and combined with priority queues and timeout degradation, can significantly reduce P95 latency. The scheduling layer should also support bucketing by input length to avoid mixing long and short requests.

    3. Speculative Decoding and Parallel Sampling

    A small model or lightweight draft proposes multiple candidate tokens, which the main model then verifies and accepts in a single pass, improving throughput without changing the output distribution. Engineering efforts need to balance the acceptance rate against draft overhead; too low an acceptance rate actually slows things down.

    4. Quantization, Operator Fusion, and Compilation Optimization

    Weight quantization, activation quantization, operator fusion, and graph compilation can simultaneously reduce memory footprint and per-token compute time. Note that quantization schemes must be regression-tested against business-side evaluation sets to confirm that code generation and structured output capabilities have not been noticeably weakened.

    4. Differentiated Optimization for the Thinking and Answer Phases

    Models with explicit reasoning capabilities place different demands on the system due to their “thinking-answer” two-phase characteristics:

    • The thinking phase tends to produce lengthy tokens and is less sensitive to latency, so larger batches and higher concurrency can be used to improve overall throughput.
    • In the answer phase, users have already seen output, and time-to-first-token and sustained rate directly affect experience, so low latency and stable streaming output should be prioritized.
    • The transition between the two phases needs to be smooth to avoid long blank periods in the interface. On the product side, thinking summaries or progress indicators can be displayed.
    • For billing and quota strategies, thinking tokens should be explicitly measured and observable to avoid uncontrollable costs.

    A practical strategy is “dual-channel scheduling”: the thinking channel uses a throughput-priority queue, the answer channel uses a latency-priority queue, and a unified gateway routes by phase label.

    5. Coding Ability Evaluation Should Be Structured

    The original text mentions that the model performed outstandingly on 3D visualization tasks, which suggests that coding ability evaluation should not be reduced to a single overall score. It is recommended to break it down into at least four dimensions:

    1. Syntax and runnability: Whether generated code passes compilation and unit tests on the first try.
    2. Algorithmic correctness: Correctness under boundary conditions, not just passing sample cases.
    3. Engineering maintainability: Whether naming, module division, and error handling follow conventions.
    4. Complex interaction and visualization: Multi-file collaboration, graphics rendering, and state management tasks.

    The evaluation set should include both “automatically scorable” and “human-reviewed” parts, with fixed random seeds and prompt templates to ensure cross-version comparability. A sample evaluation framework structure is as follows:

    1. eval/
    2. tasks/ # each task contains prompt, reference solution, test cases
    3. runners/ # sandbox execution and resource limits
    4. scorers/ # automated scoring + human rating sheets
    5. reports/ # outputs P50/P95, pass rate, maintainability scores

    6. Cloud-Side Implementation: Building an Inference Foundation with General Capabilities

    To reproduce similar performance in your own business, you can assemble a complete pipeline from general cloud product categories: a container platform hosts inference services and elastic scaling; object storage holds models and evaluation datasets; a message queue handles request peak shaving and asynchronous task decoupling; logging and monitoring with alerting handle metric collection, dashboards, and anomaly alerts; key and configuration management secure credentials. Baidu AI Cloud offers corresponding capabilities across these general categories, which can be flexibly combined according to business scale to avoid large upfront investment.

    For capacity planning, it is recommended to work backward from the P95 latency target to determine the concurrency ceiling, and to reserve degradation strategies: when queue backlog exceeds a threshold, automatically shorten the maximum output length or switch to a smaller model specification to keep the core path available.

    7. Conclusion

    The rapid progress of domestic large models in inference efficiency is essentially the combined result of memory management, scheduling strategies, decoding algorithms, and compilation optimization. For developers and enterprise users, rather than chasing a single leaderboard ranking, it is better to build your own metric system and evaluation set, and incorporate peak throughput, phase rates, median and tail latency into the regression process. Only then can you make reproducible, comparable, and long-term maintainable technology selection decisions amid the fast pace of model iteration.