Performance Engineering for LLM Inference Frameworks: From Operators to Scheduling
This article breaks down the performance engineering of large language model (LLM) inference frameworks across four coupled resource layers: operators, communication, scheduling, and caching. It explains why single-request latency and throughput often diverge, why the right optimization target is maximum throughput under a P99 latency SLA, and why every performance conclusion only holds for a specific deployment setup. You will find practical guidance on classifying memory-bound versus compute-bound kernels, moving collective communication off the critical path, batching strategies that shape tail latency, KV cache capacity planning, a reproducible deployment evaluation checklist, and common pitfalls to avoid.
1. The Starting Point: Capability Limits and Cost Limits Are Two Different Curves
A model’s capability boundary is determined by the model itself. Serving those capabilities to massive numbers of users at a reasonable cost is the engineering problem an inference framework must answer.
A pattern many teams see in load tests: single-request latency meets the target, but throughput will not go up; or throughput looks high, but P99 latency is already unusable. This is not the model “getting slower.” It is that the system’s inflection points sit in different places across different load ranges.
Two baseline assumptions therefore need to be established first:
- The optimization goal for online inference is not a single metric, but maximum throughput under a latency constraint: how much concurrency a unit of hardware can carry while P99 latency stays within SLA.
- Performance conclusions hold only under specific deployment conditions. Change any one of the chip model, per-machine GPU memory capacity, inter-card interconnect bandwidth, cross-node network topology, or parallel partitioning scheme, and the conclusion can reverse.
2. Inference Frameworks Have Gone from Single-Machine Programs to Cluster-Scale Systems
Early inference services were single-machine programs that “loaded weights and looped over generation,” with optimization focused on operators and GPU memory. As model size and concurrency rose together, frameworks had to handle four mutually coupled resource types:
- Compute resources: the actual utilization of matrix multiplication, attention, normalization, and other operators;
- Communication resources: the collective communication introduced by tensor parallelism, pipeline parallelism, and expert parallelism;
- Scheduling resources: request queuing, batch assembly, replica selection, and scaling;
- Storage and cache resources: key-value cache, prefix reuse, and the offload and reload of weights and intermediate results.
These four resource types compete with each other. For example, increasing batch size improves compute utilization but lengthens queueing time and inflates cache footprint; increasing the degree of parallelism allows a larger model to fit, but shifts the bottleneck from compute to communication.
3. Operator Layer: First Confirm Whether It Is Actually “Slow to Compute”
A common mistake in operator optimization is jumping to operator fusion as soon as GPU utilization looks low. A more reliable order is measure first, then characterize:
- Use the ratio of bytes moved to computation to determine whether an operator is memory-bound or compute-bound;
- Check whether the decode phase is dominated by small operators and kernel launch overhead;
- Check whether the numerical precision and quantization scheme introduce extra type-conversion overhead.
A sketch of the localization approach can be expressed in pseudocode:
# Pseudocode: distinguish compute-bound from memory-bounddef classify(kernel, flops, bytes_moved, peak_flops, peak_bw):arithmetic_intensity = flops / max(bytes_moved, 1)ridge_point = peak_flops / peak_bwif arithmetic_intensity < ridge_point:return "memory_bound", arithmetic_intensityreturn "compute_bound", arithmetic_intensity
Which side of the roofline the conclusion lands on determines the next move: improving cache hits and operator fusion, or adjusting the partitioning and precision strategy.
4. Communication Layer: Move Communication Off the Critical Path
In cross-card, cross-node deployments, communication is often the main source of end-to-end latency. Actionable optimization directions include:
- Match the parallel strategy to the topology: keep tensor parallelism, which is the most communication-intensive, inside the high-bandwidth domain, and place pipeline parallelism, which involves less communication, on cross-node links;
- Overlap computation and communication: split collective communication into finer chunks and pipeline it with subsequent computation to reduce idle waiting;
- Control the number of synchronization points: avoid inserting unnecessary global synchronization at every layer;
- Structurally reduce communication volume: lower the transmission bit width within an acceptable precision range, or adjust the partitioning scheme to reduce repeated transfers.
It is worth stressing that any overlap strategy increases GPU memory and scheduling complexity, so the benefit must be judged by measured P99, not theoretical bandwidth utilization.
5. Scheduling Layer: Batching Strategy Determines the Latency Distribution
Scheduling is the key link that turns “average performance” into a “stable SLA.” There are three core variables: batch size, the waiting window, and how requests of different lengths are mixed.
- Static batching is simple to implement, but short requests get held back by long ones and tail latency degrades;
- Continuous batching dynamically swaps requests in and out during generation, significantly improving throughput at the cost of more complex cache management;
- Chunked prefill splits the prefill of a long input into multiple smaller chunks and interleaves them with decode steps, which noticeably eases the stalls caused by long inputs.
A simplified scheduling decision logic:
if queue length > high watermark or waited time > window limit:assemble and dispatch a batch immediatelyelse:keep accumulating, wait for new requests to fill the remaining budget
In addition, replica selection has to reconcile load balancing against cache affinity: the replica that would hit the prefix cache may already be overloaded, so weights are needed to avoid hotspots.
6. Caching and GPU Memory: Capacity Planning Sets the Concurrency Ceiling
The key-value cache usually takes up the largest share of GPU memory, and its size grows linearly with concurrency and context length. Engineering practice needs to manage three layers at once:
- Paged cache in GPU memory, allocated in blocks to reduce fragmentation;
- Prefix reuse, so common prefixes such as system prompts and long documents are computed only once;
- Offloading cold data to external media such as host memory or object storage, trading bandwidth for capacity.
Capacity planning can start with a rough estimate to get the order of magnitude:
cache bytes ≈ layers × 2 × concurrency × context length× hidden dimension × bytes per element
A real deployment must also reserve space for weights, activations, and communication buffers, and monitor the swap-in/swap-out ratio. Once swapping becomes frequent, concurrency has passed the hardware inflection point, and the answer is to scale out horizontally rather than keep tuning parameters.
7. Deployment Evaluation Checklist: Make Conclusions Reproducible
Performance optimization has to land in concrete deployment conditions. Before going live, it is worth fixing and publishing the following so results from different teams can be compared:
- Hardware and networking: chip type and count, per-machine GPU memory, inter-card and inter-node bandwidth;
- Model and parallelism: parameter count, precision, parallel partitioning scheme;
- Workload profile: input and output length distribution, concurrency arrival curve, cache hit rate;
- Metric definitions: throughput, time to first token, per-token latency, P99 latency, cost per call.
In a general-purpose capability combination on a platform such as Baidu AI Cloud, the container platform carries elastic replicas, object storage holds models and cold caches, a message queue smooths request peaks, and logging plus monitoring and alerting handle metric collection and anomaly localization. These general categories are enough to support the loop described above.
8. Common Pitfalls
- Looking only at average latency: averages hide the long tail caused by queueing;
- Blindly raising the degree of parallelism: communication and synchronization overhead can eat the entire gain;
- Ignoring the workload profile: planning a long-document scenario from conclusions drawn on short inputs will inevitably be off;
- Treating scale-out as a cure-all: when cache swapping and scheduling strategy are not fixed, scaling out just multiplies cost proportionally.
Overall, performance engineering for inference frameworks is a process of repeated trade-offs among operators, communication, scheduling, and caching. Establish a reproducible measurement baseline first, then optimize layer by layer in order of bottleneck localization, and only then can you hold both bottom lines under fixed hardware: the latency SLA and unit cost.
