From 8f722ec60988691541523eba1898f2bd9a00839d Mon Sep 17 00:00:00 2001 From: Alex Kroman Date: Thu, 22 Oct 2026 13:22:14 -0700 Subject: [PATCH] Consume TTS requests from a deque, not list.pop(0) pop(0) shifts every remaining chunk, so a long --url/PDF text did quadratic work queueing its requests; deque.popleft() is O(1). (Aikido review.) Co-Authored-By: Claude Opus 5.5 --- aai_cli/tts/session.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aai_cli/tts/session.py b/aai_cli/tts/session.py index f498845..3cfce14 100644 --- a/aai_cli/tts/session.py +++ b/aai_cli/tts/session.py @@ -2,6 +2,7 @@ import base64 import binascii +import collections import contextlib import json from abc import abstractmethod @@ -241,10 +242,10 @@ def _run_protocol( as it arrives, so a caller can play it immediately; the full PCM is still accumulated and returned.""" sample_rate = _begin_sample_rate(ws) - pending = list(texts) + pending = collections.deque(texts) in_flight = 0 while pending and in_flight < _MAX_IN_FLIGHT: - _send_request(ws, pending.pop(0)) + _send_request(ws, pending.popleft()) in_flight += 1 pcm = bytearray() @@ -257,7 +258,7 @@ def _run_protocol( # Exactly one per Flush, in order: every byte of that request is delivered. in_flight -= 1 if pending: - _send_request(ws, pending.pop(0)) + _send_request(ws, pending.popleft()) in_flight += 1 elif mtype == "Error": raise APIError(f"TTS error {_error_frame_detail(msg)}")