Skip to content

perf(linux-screen): X11 SHM no row-copy after XShmGetImage - #3292

Open
kyzer1023 wants to merge 6 commits into
CapSoftware:mainfrom
kyzer1023:kyzer/perf-linux-x11-shm-no-row-copy-b164
Open

kyzer1023 wants to merge 6 commits into
CapSoftware:mainfrom
kyzer1023:kyzer/perf-linux-x11-shm-no-row-copy-b164

Conversation

@kyzer1023

@kyzer1023 kyzer1023 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What

X11 MIT-SHM capture publishes the XShmGetImage mapping as the ffmpeg frame when the image is packed 32-bit and the segment has 64 bytes of tail padding. The mapping stays alive until every consumer drops the frame, so the next grab cannot overwrite those pixels. Up to four in-flight frames each keep their own segment; a fifth falls back to an owned copy. GetImage path unchanged.

Why

Residual after #3145 frame pooling: every SHM grab still memcpy’d rows out of the segment. That copy is ~0.5 ms @1080p / ~2 ms @4k on this host.

Measurement

Hardware: Intel Xeon, 4 logical CPUs, x86_64, Xvfb 3840×2160×24, MIT-SHM 1.2. rustc 1.88.0. Release (opt-level=s, lto=thin, codegen-units=1). Warmup 20, 100 samples; median = mean of two central sorted samples.

Resolution Row-copy Publish wrap Full grab (copy) Full grab (publish)
1920×1080 0.493 ms ~0.00008 ms 1.298 ms 0.541 ms
3840×2160 2.004 ms ~0.00008 ms 4.267 ms 2.023 ms

row_copy_only times copy_image_rows into a reused frame. Full-grab savings exceed that memcpy because the copy path still allocates a new ffmpeg frame. Xvfb is software, so full-grab includes XShmGetImage.

Test plan

  • x11_shm_capture — 11 passed (pixel match, unaligned regions, scale, resize, lifetime after grabber drop, busy-slot fallback)
  • Timed benches above
  • Manual X11 capture spot check on a real X server

No overlap with #3281/#3287 (AVX2 YUV), or Windows MF PRs. Complements #3145 (frame pool).

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issue was found.

Summary

X11 capture can now pass shared-memory pixels directly to FFmpeg instead of copying every row.

  • Linux X11 capture can publish shared-memory pixels directly as video frames.
  • Wayland display queries wait up to one second for a reply.
  • The Linux camera job loads kernel support only when needed.
  • The screenshot harness uses Hyprland's active monitor size.

No new actionable issues were found. The comments flagged in the previous thread have been removed. Tests were not run during this review.

Reviews (6) · Last reviewed commit: "fix: allow busy Wayland compositors to e..." · Reviewed by Greptile

Publish the MIT-SHM mapping as the ffmpeg frame when the packed stride
fits, and keep that mapping alive until consumers drop the frame.

Copy link
Copy Markdown
Contributor Author

@greptileai review

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

@kyzer1023 is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor Author

@greptileai review

Copy link
Copy Markdown
Contributor Author

@greptileai review

Copy link
Copy Markdown
Contributor Author

@greptileai review

Copy link
Copy Markdown
Contributor Author

@greptileai review

Copy link
Copy Markdown
Contributor Author

@greptileai review

This branch has not been deployed

No deployments
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