freestream / docs /LATENCY.md
LoveLogicAI's picture
Roleplay-mode latency row + speculative/throttling findings complete
f908a3e verified
|
Raw History Blame Contribute Delete
6.85 kB

LATENCY β€” benchmarking methods & budget tables

MEASURED β€” MVP slice, 2026-10-04, cpu-upgrade (8 vCPU cgroup quota, CPU-only)

End-to-end run ml-intern-freestream-e2e-speculative (final: job 6ac2e756404719ba37651973, two turns, speculative dispatch ON, ASR tiny.en @1 thread, clause-level chunking): livekit-server v1.13.7 dev mode in-container, bot joined via the real CLI, test client asked spoken questions, timings measured at the receiving client.

Metric Measured Target Verdict
t_perceived, turn 1 (speculative + cached disclosure) 2.94s ≀ 4.0s (win condition) PASS πŸ”₯
t_perceived, turn 2 (speculative, dynamic reply) 5.79s β€” both turns via speculative path
t_perceived, roleplay mode (LLM agent in the loop) 7.1–7.4s relaxed (12s) HF router generation dominates
t_ready (CLI join β†’ bot ready, incl. warmup) 12.5s β€” β€”
ASR finalize (tiny.en int8, 1 thread) 1.25–1.46s 400–700ms over; standalone RTF 0.25
First-chunk synth, turn 2 4.09s 200–400ms clause-capped (was 7.47s)
bot→client transport gap 0.04s (t1) / 0.45s (t2) — negligible
cgroup CPU throttling during turns 0 periods, 0ms β€” contention myth settled
Mouth movement 13/13 checks incl. both turns >0 PASS
Replay logs both hash chains verify valid PASS

Findings from the profiling campaign:

  1. cgroup oversubscription is the #1 CPU pitfall: the container reports os.cpu_count()=64 under an 8-core quota. Whisper tiny at 8 threads measured 39.5s vs 1.16s at 1 thread (same transcript). Thread counts are pinned low (FREESTREAM_WHISPER_THREADS).
  2. The fixed consent disclosure is pre-synthesizable (CONSENT.md #2): caching it at session start removes Piper entirely from the first turn's audio path.
  3. botβ†’client transport is nearly free (0.04–0.5s) β€” measured with absolute cross-process timestamps.
  4. Speculative dispatch works (concept mitigation #1): dispatching ASR + agent + first-chunk synth at ~300ms of silence (with cancellation on speech resume and dedup against the final event) took turn 1 from 3.12s to 2.94s. Both measured turns completed via the speculative path; the cancellation path is exercised by the segmenter's "resumed" event.
  5. The contention question is settled: zero cgroup throttling (cpu.stat deltas across turns: 0 periods, 0ms). The in-context vs standalone RTF gap is not quota starvation β€” it is cold-start effects (page cache, allocator warmup) and benign thread scheduling. The ORT thread-cap countermeasure was not needed (knob FREESTREAM_ORT_THREADS remains for other hosts).
  6. First-chunk synth length was the real turn-2+ bottleneck: a 99-char first sentence cost 7.47s of synthesis. Clause-level chunking (cap ~60 chars at comma boundaries) cut it to ~4s. Later chunks pipeline behind playback.
  7. Quantization verdict β€” asymmetric: int8-dynamic-quantizing the Piper voice (63.2 β†’ 18.7 MB) made TTS 3–4Γ— slower (RTF 2.50–2.98 vs 0.79–0.86 fp32): dequant overhead dominates the conv-heavy VITS graph on this CPU (no VNNI). Rejected here; artifact + verdict archived at LoveLogicAI/piper-en_US-amy-medium-int8. ASR was already int8 (CTranslate2) and got faster via English-only tiny.en @1 thread.
  8. whisper tiny.en vs base accuracy: base transcribed the bot name "Streamy" correctly; tiny.en hears "Streami". The latency profile uses tiny.en; base (+~2s ASR) is the accuracy upgrade path.

Remaining levers, in order of expected yield: (a) the 0.9s of unexplained utterance-finalization lag beyond the 600ms hangover; (b) in-context ASR/synth contention (standalone RTF 0.25/0.79 vs in-context ~0.5/1.2) β€” the render loop is exonerated, so the suspect is WebRTC encode + thread interference; (c) the concept's speculative dispatch at ~600ms silence (overlaps agent response with utterance tail) β€” the largest structural win for turn-2+, but a bigger build.

The tables below are the original design targets, kept for reference.

Budget (from the concept package; measured results above)

These are the targets the MVP slice was designed against; the MEASURED section above is the current scorecard against them.

Stage Local CPU-only Local + GPU/ANE Pika (published)
ASR finalize 400–700ms 150–250ms β€”
Agent first token 300–900ms 150–400ms β€”
TTS first chunk 200–400ms 80–150ms β€”
Avatar render 500–900ms 200–350ms β€”
Perceived turn ~2.5–4.5s ~1.2–2.0s ~1.5s

The mitigations that make 2.5s feel like 1.5s

  1. Speculative dispatch at ~600ms of silence β€” partial ASR transcripts go to the agent before the utterance finalizes; resumed speech cancels the generation. Saves 200–600ms.
  2. Sentence-level pre-roll β€” the agent's first sentence starts TTS while later sentences are still generating. Saves one TTS round-trip.
  3. Lead-out motion β€” avatar mouth motion starts ~150ms before audio playout, perceptually erasing the render handshake.
  4. Cached identity β€” avatar/voice assets are loaded and warmed at session start, never per turn.

Fidelity ladder rungs & FPS targets

Rung Name Target FPS Host
4 FULL_PORTRAIT 20–24 GPU / Apple ANE
3 VISEME_STILL β‰₯15 (MVP) CPU
2 AUDIO_REACTIVE_WAVE β‰₯10 CPU (weak)
1 STATIC_CARD n/a anything

Rung selection is select_rung() at join time; runtime degradation triggers when measured FPS < target for 5 consecutive seconds (event: persona.rung_change).

Benchmark harness (MVP acceptance)

python benchmarks/turn_latency.py (lands with the MVP slice) measures, per turn over β‰₯50 synthetic Q&A turns:

  • t_asr_final: speech-end β†’ final transcript
  • t_first_token: transcript β†’ agent first sentence
  • t_tts_chunk: sentence β†’ first audio chunk
  • t_avatar_frame: audio chunk β†’ first frame on the virtual camera
  • t_perceived: speech-end β†’ first audible+visible output

Win condition from the concept: agent joins, answers within 4s with a moving mouth, leaves, and produces a valid replay log β€” i.e. t_perceived p50 < 4.0s on CPU at rung 3, and EventLog(...).verify() == (True, None).

Reporting rules

  • Report p50/p95, machine, and library versions with every number.
  • Faster-whisper int8, Piper medium voices; note thread counts.
  • If FULL_PORTRAIT can't hold 20 FPS on Apple Silicon, video becomes a cloud-burst feature and rung 3 becomes the local ceiling β€” that is a finding to report, not a failure to hide.