perf(echo): decode off the event loop so uploads are not starved - #68
Open
rickstaa wants to merge 1 commit into
Open
perf(echo): decode off the event loop so uploads are not starved#68rickstaa wants to merge 1 commit into
rickstaa wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Max gap roughly halved, startup 0.45 s faster, about 40% more delivery events per run.
No regressions: video-only
bluris unchanged at 0.42 s max gap, and file-inputrobotstill returnsh264+opuswith a complete audio track.Scope
Partial fix. Video-only sits at 0.42 s and
robotis 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.