Skip to content

perf(voice): add latency instrumentation and parallelize memory fetch - #96

Draft
xinghaohuang91 wants to merge 1 commit into
mainfrom
latency/voice-latency-testing
Draft

perf(voice): add latency instrumentation and parallelize memory fetch#96
xinghaohuang91 wants to merge 1 commit into
mainfrom
latency/voice-latency-testing

Conversation

@xinghaohuang91

Copy link
Copy Markdown
Contributor

Summary

  • Adds INFO-level latency logging across the Voice channel's per-turn pipeline (setup→first-prompt, CO poll/init, memory retrieval, LLM callback, time-to-first-token, streaming completion) so voice latency can be measured end-to-end against live calls.
  • Parallelizes TAC.retrieve_memory()'s get_profile() and retrieve_memory() calls via asyncio.gather, since the memory recall call only needs the already-known profile_id, not the profile fetch result.
  • Adds VOICE_LATENCY_ANALYSIS.md documenting live-call latency test results (cross-checked against Twilio ConversationRelay/Voice Insights event timelines), root causes identified, and remaining optimization ideas (notably: BaseAPIClient creates a new httpx.AsyncClient per request with no connection reuse — likely the next highest-impact fix, not yet implemented).

Draft — opened to snapshot in-progress latency testing work; not ready for review yet, more optimization work planned as a follow-up.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Release / version bump

Checklist

  • Tests added/updated (existing test_tac.py / test_voice_channel.py suites pass unchanged)
  • Documentation updated (VOICE_LATENCY_ANALYSIS.md)
  • Tested E2E (live phone calls via voice_streaming.py + Twilio Voice Insights)

SDK Parity

  • Change is Python-specific (no TypeScript update needed)

🤖 Generated with Claude Code

Adds INFO-level timing logs across the Voice channel's per-turn pipeline
(setup-to-first-prompt, CO poll/init, memory retrieval, LLM callback,
time-to-first-token, streaming completion) to make voice latency testable
end-to-end against live calls.

Also parallelizes TAC.retrieve_memory()'s get_profile() and
retrieve_memory() calls via asyncio.gather, since the memory recall call
only needs the already-known profile_id and doesn't depend on the profile
fetch result.

Includes a written analysis of latency test calls (cross-checked against
Twilio ConversationRelay/Voice Insights event timelines) documenting
findings and remaining optimization ideas.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant