Chatbot latency profile
One chat turn, two architectures, measured against the real claude CLI with the
project's own flags, models and prompts. Pattern A spawns three separate one-shot
processes (input guardrail → main agent → output guardrail). Pattern B runs all three as
sequential messages inside one persistent process. Each bar segment is a mean over 5 iterations.
Pattern A · turn
3 processes, sequential
Pattern B · turn
1 persistent process
B saves
–
…of which cold-start
the rest is warm-context speedup
Each stage is its own cold claude -p. Cold start and a long time-to-first-token are paid three times.
Cold start is paid once, up front. The guardrail stages become cheap warm follow-up messages. Same time axis as above.
Consolidating three processes into one warm process cuts the turn roughly in half (– → –). But only about of that saving comes from paying the ~2 s Node cold start once instead of three times.
The bigger loss in Pattern A is that each guardrail runs as a full cold inference: the haiku input guardrail spends – just reaching its first token (thinking + a fresh, un-cached system prompt on every spawn) for what is a one-word verdict. In Pattern B the same check, sent into an already-warm context, reaches first token in – and generates in well under a second.
The main agent's generation (–) is the irreducible core in both — it is real answer tokens. Attack the guardrail overhead, not the answer.
| Iteration | A · input grd | A · main | A · output grd | A · turn | B · cold | B · turn |
|---|
Iteration 0 is a warm-up (disk / CLI cache cold) — shown muted, included in means.
claude CLI v2.1.212. Cold start = wall time from Process.Start to the CLI's system/init event; time-to-first-token and generation come from the CLI's own result event (ttft_ms, duration_ms). The app's own code was not modified.haiku with --json-schema (as shipped). Pattern B cannot switch model or schema per message inside one process, so its guardrail stages run on sonnet with the instruction inline — yet they are still far faster, because the context is warm. This strengthens, not weakens, the conclusion.—