Skip to content

perf: convert BGRA pixels to RGB in bounded chunks - #611

Open
Wimpykid1a wants to merge 1 commit into
BoboTiG:mainfrom
Wimpykid1a:nightly/issue-522
Open

Wimpykid1a wants to merge 1 commit into
BoboTiG:mainfrom
Wimpykid1a:nightly/issue-522

Conversation

@Wimpykid1a

Copy link
Copy Markdown

Refs #522.

ScreenShot.rgb converts the input to contiguous bytes in 8,192-pixel chunks before taking the channel slices. This bounds the temporary buffers while keeping the packed RGB output available as a writable memoryview.

In an isolated Linux/WSL process with CPython 3.10.12, median first-access time for synthetic 3840×2160 data went from 338.94 ms to 77.97 ms. Peak traced Python allocations beyond the output dropped from 16,201 KiB to 65 KiB. These numbers measure pixel conversion.

  • Tests cover channel order across chunk boundaries and a short final chunk. The 20 display-free RGB, Pillow, and NumPy cases passed.
  • Documentation and the 11.0 release notes describe the conversion change.
  • The offline check.sh run hit the Python 3.10 type target on unrelated files. Ruff format and lint passed. Mypy passed on all 67 source files when targeting Python 3.14.
  • The strict offline docs build rendered the release note and reported the same 20 warnings as the original tree. The local runtime lacked Xvfb and libxcb-randr for the display-dependent suite.

AI assistance disclosure

Codex generated the implementation, test, and release note and ran the reported checks.

@BoboTiG

BoboTiG commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Tested locally on Linux, and the improvement is real! Thanks @Wimpykid1a.

Comment thread src/mss/screenshot.py
rgb[2::3] = raw[::4]
# Slice contiguous bytes instead of strided memoryviews. Copying in
# chunks keeps the temporary buffers small for large screenshots.
pixels_per_chunk = 8192

@BoboTiG BoboTiG Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sould we create a contant at the top of the file? So that if someone wants to test other values for their local setup, it will be easier. And it should be part of the documentation also.

@BoboTiG

BoboTiG commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

@jholveck & @halldorfannar how does it sounds to you?

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.

2 participants