Skip to content

perf: obs-ffmpeg-mux: one write per packet on the mux pipe #3211

Closed

Description

@zackees

What

plugins/obs-ffmpeg/obs-ffmpeg-mux.c.h:615-622 writes the info header and the data separately (util/pipe-posix.c.h:182-194): two syscalls for large packets.

Proposed change

writev on the raw fd, or coalesce small headers.

Acceptance criteria

  • Before/after numbers (strace -c -e write on ffmpeg-mux over 60 s) in the PR; nothing lands unmeasured.
  • RED then GREEN; Tier 3 parity stays bit-exact unless this issue says otherwise.

Found by a read-only code scout and not yet measured. Parent: #3176.

Activity

  1. added
    enhancement
    P3
    size:S
    on Oct 31, 2026
  2. zackees commented on Oct 31, 2026

    @zackees
    MemberAuthor

    /ready

  3. added
    ready
    on Oct 31, 2026
  4. zackees commented on Nov 1, 2026

    @zackees
    MemberAuthor

    Claiming: perf: obs-ffmpeg-mux one write per packet on the mux pipe

    What I found: the shipped os_process_pipe_write is Rust (rust/obs-util/src/platform/unix/pipe.rs). It writes straight to the child's stdin with no buffering, so every packet costs two write syscalls: the 32-byte ffm_packet_info, then the data. That includes small audio packets, which the C fwrite used to coalesce in its stdio buffer.

    Plan, one PR:

    1. RED: a new cmocka test that compiles obs-ffmpeg-mux.c.h against a counting os_process_pipe_write and checks one call per packet below the threshold, and that the child receives the same byte stream (info, then data).
    2. GREEN: write_packet copies the info and the data into a reused per-stream buffer and makes one os_process_pipe_write when the packet is at most 64 KiB. Larger packets keep the two writes, since a copy of a large packet costs more than the syscall it saves. No public header and no pipe semantics change.
    3. Numbers: syscalls per packet, and strace -c -e write on a short headless recording if I can run one here; I'll say so if not.

    Decisions: no new libobs API (a writev export would need a public header), so the coalescing stays in the plugin. First PR next tick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3enhancementreadysize:S

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions