LLM·Dex
LatencyPerformanceProduction

Why Most LLM Latency Optimizations Don't Work

P50 fast, P99 awful. Why the standard latency-optimization advice fails for production AI products, and what actually moves the needle.

By LLMDex Editorial

Every production LLM deployment hits the same wall around the six-month mark: P50 latency looks great on a dashboard, but P99 latency is unacceptable for real users. The standard advice, pick a faster model, reduce token count, cache aggressively, addresses the symptom rather than the cause. The cause is structural: LLM inference latency has a long tail because the underlying systems have a long tail, and most optimizations only attack the median.

This piece is the working playbook for actually moving the latency distribution, not just the median. It assumes you've already done the obvious things (smaller model, prompt caching, streaming) and you're still seeing P99 spikes that feel intolerable.

What "fast enough" actually means

Three latency targets define typical AI product UX:

  • Conversational chat: P50 < 500ms first-token, P95 < 1.5s, P99 < 3s
  • Inline code completion: P50 < 200ms, P95 < 500ms, P99 < 1s
  • Realtime voice: P50 < 350ms first-token, P95 < 600ms, P99 < 1s
  • Async background jobs: P95 matters; P99 less so

Note the gap between P50 and P99. Real users feel P99 most. A median-fast deployment with bad tail latency feels broken to users, they hit the slow case enough times to lose trust in the product.

Why P99 is structurally bad

Three sources of long-tail latency:

Provider-side queueing

Commercial APIs serve traffic from many customers on shared GPU pools. When the pool is hot, your request queues. Queue depth is invisible to you, but your latency reflects it. P99 spikes typically correlate with the provider's overall load.

You can't fix this directly with retries or caching. It's a structural property of shared infrastructure.

Variable token output length

A query that returns 50 tokens completes in (say) 500ms. A query that returns 500 tokens takes 5x longer. P99 latency is dominated by the long-output cases, not the cases where the prompt or model are slow.

Without explicit output-length controls, your latency distribution is shaped by your prompts' tendency to elicit long responses. This often happens accidentally, a prompt that asked the model to "explain in detail" produces a 2000-token response that takes 20 seconds.

Reasoning model variance

Reasoning models (o3, o4, DeepSeek-R1, GPT-5 with thinking) produce variable amounts of internal reasoning. A simple query might use 200 reasoning tokens; a hard query 5,000+. Total latency varies 10-50x as a result.

If you're routing queries to a reasoning model based on complexity-detection, the P99 is dominated by the hard queries. Even a small fraction of hard queries can move P99 dramatically.

Optimizations that actually help

Six optimizations, ordered by impact on the tail.

1. Aggressive output-length capping

Set max_tokens to a tight bound for every workload. If the typical answer is 200 tokens, set max to 300, not the model's default of 4000. This prevents runaway long responses that dominate P99.

Implementation note: ship a fallback for cases where the response gets truncated. "If the model hits the cap, we summarize and present a 'show more' option" works for many UX patterns.

2. Streaming-first architecture

Return tokens as they're generated, not after the full response is complete. From the user's perspective, "first useful token" matters more than "complete response." A streaming response that finishes in 4 seconds feels faster than a non-streaming one that finishes in 1.5 seconds, because the user starts reading at 200ms.

Most production AI products in 2026 should be streaming by default. If yours isn't, this is the highest-ROI change you can make.

3. Per-route model choice

A single model for everything optimizes for nothing. Production AI products should route different query types to different models:

  • Simple classification → tiny fast model
  • Standard chat → mini-tier model
  • Hard reasoning → flagship or reasoning model
  • Vision-heavy → multimodal model

Per-route latency budgets are dramatically tighter than a universal latency budget. Routing implementation costs roughly two engineer-weeks; the latency improvements compound forever.

4. Provider redundancy

Set up multi-provider failover. If your primary provider's P99 latency spikes (because their pool is hot, or a region is degraded), reroute to a secondary provider. Tools like LiteLLM or OpenRouter make this implementation cheap.

The latency benefit isn't from the secondary being faster, it's from cutting off the worst tail of the primary. If your primary is normally fast but occasionally has 30s spikes, a 5s timeout + failover gives you P99 of 5s + secondary's normal latency.

5. Speculative decoding (for self-hosted)

If you self-host, run a small draft model alongside the main model. The draft predicts tokens; the main model verifies in parallel. Throughput improves 30-50%, and the latency improvement is concentrated in the long-output tail.

This is one of the few optimizations that specifically improves P99, not just median. For self-hosted production deployments, it's worth the implementation cost.

6. Prefix caching where applicable

Most LLM workloads have stable prefixes, system prompts, retrieved-context blocks, conversation history. Prefix caching reuses the KV cache from previous requests with the same prefix, eliminating the prefill compute.

OpenAI offers this as a 50% discount when applicable. Anthropic offers it explicitly via prompt caching. Self-hosted vLLM/SGLang support it. The implementation is straightforward but underused, many teams don't structure their prompts to take advantage.

Optimizations that mostly don't help

Three popular optimizations that have less impact than people expect:

Smaller model. The relationship between model size and latency is non-linear. A 70B model isn't 10x slower than a 7B model, it's typically 2-3x slower at the same throughput. The latency win from going smaller is modest; the quality loss is real.

Prompt shortening. Reducing prompt tokens from 5K to 2K saves a few hundred ms on prefill. That's nice but not transformative. The output tokens dominate total latency.

Hardware upgrades. H100 → H200 helps throughput more than tail latency. The bottlenecks at P99 are usually queueing, output length, or reasoning variance, not raw compute speed.

The tail-killer pattern

The single most-effective pattern we've seen for fixing P99 in production:

Hard timeout + degraded fallback. Set a hard latency budget (e.g., 3 seconds for chat). If the primary model doesn't return within budget, fall back to a faster model with a smaller-context request, return that result, and log the slow case for analysis.

This pattern explicitly trades quality on the slow tail for predictable latency. It works because:

  1. Most users prefer "slightly worse answer in 3 seconds" over "best answer in 15 seconds"
  2. The slow cases tend to be hard queries where the marginal quality gain is small anyway
  3. You can analyze the slow-case logs and address the underlying causes systematically

Implementation is straightforward. Set a Promise.race between the primary call and a timer. On timeout, cancel the primary and call the fallback.

Most teams don't do this because it feels like giving up on quality. The right framing is: you're trading P99 quality for P99 latency. For most products, that's the right trade.

Concrete recommendation

If you're shipping a production AI product and P99 latency is a problem:

  1. Verify the diagnosis. Get real P50/P95/P99 numbers from production traffic. Most teams measure P50 and assume the rest is fine.
  2. Cap output length aggressively. Most P99 issues are dominated by long outputs.
  3. Stream by default. First-token latency matters more than full-response latency.
  4. Per-route model choice. Don't use one model for everything.
  5. Hard timeouts with fallback. Trade tail quality for tail latency. Log the slow cases.
  6. Multi-provider redundancy. Cut off the worst spikes by failing over.

These six steps move P99 dramatically more than any model change. Most teams under-invest in these because they feel less interesting than "switch to a faster model." The boring fixes work.

Further reading

Keep reading

Friday digest

Intelligence, distilled weekly.

One short email every Friday, new model launches, leaderboard moves, and pricing drops. Curated by hand. Free, no spam.