Skip to content

perf(echo): decode off the event loop so uploads are not starved - #68

Open
rickstaa wants to merge 1 commit into
mainfrom
rs/echo-decode-off-loop
Open

perf(echo): decode off the event loop so uploads are not starved#68
rickstaa wants to merge 1 commit into
mainfrom
rs/echo-decode-off-loop

Conversation

@rickstaa

Copy link
Copy Markdown
Member

PyAV's decode() is a blocking generator, so driving the publish loop directly from it stalls the async segment uploads for the duration of every decode. This moves it to a worker thread behind a small queue.

Applies to every mode, not just robot — video-only simply never showed enough symptom to notice.

Measured

Live webcam plus microphone through --mode robot, three runs each, same session:

first byte max gap between segments reaching the wire
before 3.34 / 3.37 / 3.36 s 0.98 / 1.11 / 1.00 s
after 2.89 / 2.92 / 2.90 s 0.62 / 0.63 / 0.63 s

Max gap roughly halved, startup 0.45 s faster, about 40% more delivery events per run.

No regressions: video-only blur is unchanged at 0.42 s max gap, and file-input robot still returns h264 + opus with a complete audio track.

Scope

Partial fix. Video-only sits at 0.42 s and robot is still 0.62 s after this, so live playback with audio remains choppier than without. The remainder is unattributed and tracked in #67.

The queue is deliberately small (8 frames) so it decouples decode from upload without adding buffering latency.

PyAV's decode() is a blocking generator, so driving the publish loop from
it directly stalls the async segment uploads for the duration of each
decode. Moving it to a worker thread behind a small queue halves the gap
between segments reaching the wire and cuts startup latency.

Measured over three runs each, live webcam plus microphone through robot:
max gap 0.98-1.11s to 0.62-0.63s, first byte 3.36s to 2.90s. Video-only
blur is unchanged at 0.42s, so nothing regresses for the other modes.

This does not fully close the gap to video-only. The rest is tracked in
#67.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 12, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants