Why LLM Code Review Is Slow and Drops Connections

    This article breaks down why large language model code reviews can be slow and prone to disconnects during long-context, reasoning-heavy tasks. It models end-to-end latency as queue time, prefill, decode, and network overhead, then explains three common bottlenecks: overly long reasoning chains, low prefix cache hit rates, and poor token efficiency. It also covers reconnection costs, a reproducible evaluation method with key metrics, and architecture-level optimizations such as layered review, retrieval-first context, task orchestration, result caching, and observability to make delivery times predictable.

    1. The Symptom: A Code Review That Never Finishes

    In a real engineering exercise, a team used an AI coding tool to review a medium-sized repository. Three model services performed very differently: the first returned results in about 4 minutes, the second in about 7 minutes, and the third ran for 40 minutes without producing a usable conclusion, with multiple connection drops and reconnects along the way.

    This is not about ranking vendors or products. The point is to abstract the issue into a general engineering problem: in long-context, reasoning-heavy tasks, what determines end-to-end inference latency, and what can engineering teams optimize?

    On the surface, the slow model inherited two features that look advanced:

    • Very long reasoning chains (deep thinking enabled by default in reasoning modes);
    • Very high output speed (a high number of tokens per second).

    But it lacked two critical capabilities:

    • High cache hit rate (insufficient prefix/context reuse);
    • High token efficiency (more input and output tokens needed for the same task).

    The result: it outputs fast, but there is too much to output; it thinks deeply, but deep enough to never converge; and with low caching, every round recomputes from scratch.

    2. Breaking Down “Slow”: Four Components of End-to-End Latency

    To diagnose slowness, start with a latency model. A request’s end-to-end time can be approximated as four segments:

    1. T_total = T_queue + T_prefill + T_decode + T_network
    • T_queue: queue wait time, affected by concurrency and quotas;
    • T_prefill: prefill time, strongly correlated with input token volume; cache hits can reduce it significantly;
    • T_decode: decode time, roughly output tokens ÷ output speed;
    • T_network: network and reconnection overhead; an unstable long connection can amplify it substantially.

    Plugging in observed data explains the paradox of “fast output but slowest overall”:

    1. Model A: 2k output tokens at 50 tokens/s -> decode ≈ 40s
    2. Model C: 20k output tokens at 50 tokens/s -> decode ≈ 400s
    3. Add repeated prefill from low caching and multiple reconnects, and 40 minutes is not surprising.

    Conclusion: output speed only affects the denominator in T_decode, while token efficiency and cache hits affect the numerator and T_prefill. When the numerator is out of control, a larger denominator does not help.

    3. Mechanism Analysis of Three Bottlenecks

    3.1 Overly Long Reasoning Chains: Depth Does Not Equal Value

    Reasoning models generate intermediate thinking to improve accuracy on complex tasks, but longer is not always better. When the task is clearly bounded, such as “locate the problem and suggest a fix,” excessive reasoning yields diminishing returns and can introduce self-doubt and repeated verification, so output never converges.

    Engineering recommendations:

    • Tier tasks: use a low-reasoning mode for simple reviews and enable deep thinking only for complex architecture reviews;
    • State an explicit output limit and stopping condition in the prompt, such as a cap on the number of issues and severity levels;
    • Split large tasks into smaller parallel tasks to shorten each chain.

    3.2 Low Cache Hit Rate: Repeated Prefill Is the Hidden Killer

    Prefix caching (context reuse) depends on stable, alignable prefixes across requests. If every request prepends the entire repository, specification documents, and prior conversation, with tiny differences in order or content, the cache largely misses and T_prefill is paid in full repeatedly.

    General ways to improve hit rate:

    • Fix the order of “system prompt + guidelines + examples” and put changing content at the end;
    • Control context size per request; retrieve on demand instead of stuffing everything in;
    • Keep the prefix consistent within a session and avoid needless rewrites.

    Illustrative structure:

    1. [Fixed prefix: role/guidelines/output format]
    2. [Semi-fixed: repository conventions and directory notes]
    3. [Volatile: current diff and retrieved snippets]

    3.3 Low Token Efficiency: More Words for the Same Task

    Token efficiency is the total tokens consumed to complete a task. Low efficiency usually comes from verbose restatement, repeated quoting of large code blocks, and unstable output formats that trigger retries. It raises both T_prefill and T_decode, a double penalty.

    Optimization options:

    • Require “conclusions and the minimal necessary patch only”; forbid restating the original text;
    • Constrain fields with structured output to reduce free-form generation;
    • Cap truncation and retries for failed requests to avoid infinite loops.

    4. Frequent Reconnects: The Underrated Stability Cost

    Long tasks are highly sensitive to connection stability. One reconnect can mean retransmitting context, invalidating cache, and discarding generated content, showing up as “ran for a long time but got nothing.”

    Engineering recommendations:

    • Use streaming responses and persist intermediate results promptly to avoid total loss;
    • Set reasonable timeouts and idempotent retries; reuse the same prefix on retry to preserve cache;
    • Slice long tasks so a single failed slice only reruns that slice;
    • Monitor reconnect rate, time to first token, and completion rate with alerts.

    5. A Reproducible Evaluation Method: Do Not Choose by Gut Feeling

    Build an internal evaluation set with fixed tasks and criteria, and record these metrics:

    Metric Meaning Focus
    Completion rate Share of cases producing usable results within the time limit Primary metric
    End-to-end latency From request to usable result Consider task size
    Input/output tokens Total consumption per task Reflects efficiency
    Cache hit rate Prefix reuse ratio Affects prefill
    Reconnect rate Connection drops per request Stability
    First-pass rate Share needing no major manual rework Quality

    Evaluation pseudocode:

    1. def evaluate(case, model, timeout=600):
    2. start = now()
    3. try:
    4. resp = call(model, case.prompt, stream=True, timeout=timeout)
    5. tokens = resp.usage # input/output tokens
    6. cache = resp.cache_hit_rate # cache hit rate
    7. return {
    8. "ok": True,
    9. "latency": now() - start,
    10. "tokens": tokens,
    11. "cache": cache,
    12. "retries": resp.retries,
    13. }
    14. except TimeoutError:
    15. return {"ok": False, "latency": now() - start}

    6. Architecture-Level Ways to Reduce Load

    • Layered review: filter with lightweight rules and static checks first, then send hard cases to the model;
    • Retrieval first: inject only snippets relevant to the change to control context size;
    • Task orchestration: split review into steps such as “understand change → locate risk → generate patch → self-check,” each with a length limit;
    • Result caching: reuse prior conclusions for identical diffs;
    • Observability: connect logging and monitoring/alerting to build a closed-loop dashboard for latency, tokens, and reconnects.

    If using general cloud capabilities, you can combine object storage for intermediate artifacts, a message queue for peak shaving, a container platform for concurrent workers, and logging/monitoring services for diagnosis. These are generic categories and do not involve any proprietary interfaces.

    7. Conclusion

    “Slow and dropping connections” is usually not a single cause but the combined effect of overly long reasoning, insufficient caching, low token efficiency, and unstable connections. When choosing a model, do not look only at output speed or reasoning depth. Focus on completion rate and end-to-end latency, and build a reproducible evaluation. On the engineering side, use task tiering, context governance, streaming persistence, and observability to turn uncontrollable long-tail latency into predictable delivery times.