[codex] speed up BLE image preparation#21
Merged
g4bri3lDev merged 5 commits intoMay 12, 2026
Conversation
LordMike
commented
May 7, 2026
LordMike
commented
May 7, 2026
82dd583 to
9536527
Compare
9536527 to
9bde2b3
Compare
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
Fixes #17.
This PR makes BLE image uploads avoid the slow internal JPEG round trip and reduces the CPU cost of preparing display bytes.
drawcustomoutput as a PIL image inside the integration until a destination actually needs JPEG./imguploadand Home Assistant image previews.PIL -> JPEG -> PILinternally.dither=0usingImage.getcolors(maxcolors=len(palette)).Key Commits
e72b609- internal image formatdrawcustomnow keeps generated images as PIL images internally.c6fabd1- BLE preparation optimizationdither=0skips palette mapping when every pixel is already an exact display-palette color.0-5now packs bytes with vectorized operations.1233130- direct-write compression selection50 KiBMCU compressed buffer limit.fc034d4- drawcustom upload timing logsTiming Context
The original report came from issue #17, where my ARM Home Assistant server took about
29sto process a960x640image in the current path. That CPU-bound work ran on the HA event loop, so HA's HTTP server stopped responding during the call; in practice,drawcustomservice calls timed out in the browser while the upload continued in the background.The largest panel size I found was
2560x1440, so this PR uses that as a practical worst case. It has exactly6xas many pixels as960x640, so linear scaling on my ARM host implies roughly174sin the original path.Local original timings were measured on a much faster x64 CPU and should be read only as lower-bound comparison data, not representative of my HA server:
2560x1440, scheme 4,dither=0, original path: roughly10-11.4sdepending on image content.2560x1440, optimized candidate: roughly0.50-0.54sfor vectorized process + encode + zlib.2560x1440, exact-palette skip path: roughly0.006sdetection plus0.051sdirect-write encoding.The ARM host should benefit strongly because this removes the expensive Python per-pixel loops and moves the remaining CPU-heavy BLE preparation into executor jobs, keeping HA responsive while the work runs.
Validation
custom_components/opendisplaypassed.0-5.