perf: MIT-SHM capture + codec hot-path allocations - #23
Merged
Merged
Conversation
- The encoder reused to allocate a fresh ~3 MiB I420 buffer per frame; it now keeps a YUVBuffer and rewrites it via read_bgra8 when dimensions match (~190 MB/s of alloc churn removed at 60 fps). - Decode emitted I420→RGB8 then expanded to BGRA with a scalar loop. write_rgba8 does the conversion in one SIMD pass (AVX2 on x86-64) and the R↔B swap for the RawFrame BGRA contract vectorizes in place. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
GetImage serializes every frame through the X socket — ~8 MiB per 1080p frame — plus a reply round-trip. With MIT-SHM >= 1.2 the server writes the pixmap into a shared segment (CreateSegment fd passing, mapped via memmap2) and replies with a completion event, so capture is one memcpy off mapped memory. The backend probes SHM at connect and falls back to plain GetImage on older servers, remote displays (ssh -X), or any runtime failure. Verified live against Xvfb (shm segment present, repeated captures correct). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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.
Summary
CreateSegmentfd-passing, SHM ≥1.2): the server writes the pixmap into a shared segment mapped viamemmap2; a 1080p frame costs a completion event + memcpy instead of ~8 MiB serialized through the X socket. PlainGetImageremains the fallback for remote/older servers and runtime failures. Verified live against Xvfb (shmpresent, repeated captures correct,shm_detachon drop).H264Encoderkeeps itsYUVBufferacross frames (read_bgra8rewrite on same dims) — ~3 MiB alloc per frame removed (~190 MB/s at 60 fps).write_rgba8(AVX2 path) + in-place R↔B swap, replacing an RGB8 scratch buffer + scalar expand per frame.Test plan
cargo test -p rds-desktop --features x11— codec + new livecapture_roundtrip(Xvfb) greencargo test --workspace --all-targets --all-features— 0 failurescargo clippy -p rds-desktop --all-targets --features x11 -D warnings+cargo fmt --check+cargo machete— cleancargo deny/cargo-audit— not installed locally; covered by CI supply-chain lane (new dep:memmap20.9, MIT/Apache-2.0, widely used)Generated with Devin