Skip to content

fix(cli): drain stdin in pipe-sized reads - #60

Closed
fperex wants to merge 1 commit into
mainfrom
fix/cli-stdin-read-size
Closed

fperex wants to merge 1 commit into
mainfrom
fix/cli-stdin-read-size

Conversation

@fperex

@fperex fperex commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Problem

moq import read stdin into an empty BytesMut, which offers 64 bytes per read, and each tokio stdin read is a blocking-pool round trip. On a loaded host the importer drained a keyframe slower than it arrived, so audio muxed behind it reached subscribers late.

Fix

Allocate the read buffer with a 64 KiB capacity (the default Linux pipe size). buffer.clear() keeps that capacity, so every read offers 64 KiB.

Test

publish::tests::stdin_drains_in_pipe_sized_reads decodes bbb_cbr.ts (144,948 bytes) through a counting pipe with paused time. On main it takes 2,266 reads; with the fix 4. Deterministic, no wall clock. just check passes.

Local measurement (7 alternating pairs, unoptimized test builds, idle Mac, 5.4 MB TS piped through cat): median 84,448 reads / 856.6 ms on main versus 83 reads / 65.9 ms with the fix. This is a decode-path measurement, not an end-to-end latency result.

API and wire

None.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

`moq import` read stdin into an empty `BytesMut`, which offers 64 bytes
per read, and every tokio stdin read is a blocking-pool round trip. On a
loaded Linux runner that capped the importer near 1 MB/s, so each video
keyframe burst held the audio muxed behind it for hundreds of
milliseconds, past the player's fixed 250 ms delay. Reads now take up to
64 KiB, a default Linux pipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fperex

fperex commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner Author

Correction: this PR is not blocked. The silence I described was caused by the fork's own player, which ignored the catalog jitter floor and held Auto near 40 ms. Main's player sets the Auto target to max(measured, advertised) plus one frame, and the MPEG-TS importer advertises its PES burst as that floor, so a newest-first flush is covered.

Checked on main (212110f) with only this change applied, on a Linux host: upstream relay, importer and demo watch page, AAC 44.1 kHz speech with BBB video through ffmpeg into moq import ts, near-zero shaper and loopback, 11 rows with this PR and 11 without, interleaved, across Playwright Firefox, native Firefox 157 and Playwright Chromium:

main main + this PR
Silence episodes none none
Auto target after 10 s 209 ms 209 ms
Advertised audio jitter 186 ms 186 ms
Firefox underruns, 50 s window, median 3 to 5 0
Chromium dropouts of 20 ms or more, median 10 2
Publisher CPU (ffmpeg plus importer) about 0.08 cores about 0.02 cores

With -pes_payload_size 0 -muxdelay 0 both sides were clean (target 116 ms).

(Written by Claude Opus 5.5)

@fperex fperex changed the title fix(cli): drain stdin in pipe-sized reads fix(cli): drain stdin in pipe-sized reads (blocked on jitter fix) Oct 6, 2026
@fperex fperex changed the title fix(cli): drain stdin in pipe-sized reads (blocked on jitter fix) fix(cli): drain stdin in pipe-sized reads Oct 7, 2026
@fperex

fperex commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

Closing: this fix is included in #3 on top of current main. (Written by Claude Opus 5.5)

@fperex fperex closed this Oct 7, 2026
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