perf: defer full-frame compression when a partial upload may succeed#95
Merged
Merged
Conversation
upload_image always encoded and zlib-compressed the whole frame before attempting the partial (0x76) path. When the partial upload succeeds, that compression (2.7ms @800x480, 15.7ms @1600x1200) is pure waste. Skip it when state is not None by preparing with compress=False, and compress lazily in _dispatch_upload on the full-upload fallback. The zipxl path already recompressed on window mismatch; extend the same lazy behavior to the non-zipxl branch so the fallback produces byte-identical output to before. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRrm95f1qNZzDM9r2SB6KW
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
3 tasks
g4bri3lDev
added a commit
to balloob/py-opendisplay
that referenced
this pull request
Jul 5, 2026
Semantic conflict between OpenDisplay#95 and OpenDisplay#96: the lazy compression branch for non-ZIPXL devices referenced DEFAULT_ZLIB_WINDOW_BITS, which device.py never imported (NameError at runtime), and even spelled correctly a 15-bit window is rejected by current firmware — prepare_image has compressed everything at 9 bits since OpenDisplay#96. The deferred path now uses the same 9-bit window. ZIPXL window repair and the non-ZIPXL 50KB size gate keep their existing behavior.
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
upload_imagealways encoded and zlib-compressed the entire frame before attempting the partial (0x76) path. When the partial upload succeeds (the common case for small changes), that full-frame compression is pure waste — 2.7 ms @800×480, 15.7 ms @1600×1200.This PR defers full-frame compression when
state is not None:upload_imageprepares withcompress=Falsewhen a partial upload may be attempted._dispatch_uploadcompresses lazily on the full-upload fallback. The ZIPXL path already recompressed on window mismatch; this extends the same lazy behavior to the non-ZIPXL branch.Correctness
state is None(plain full upload): unchanged —prepare_imagestill compresses eagerly, and_dispatch_upload's newelif compressed_data is Nonebranch is never taken.state is not None, partial succeeds: full-frame compression skipped entirely (the win).state is not None, fallback to full:_dispatch_uploadcompresses with the same window bitsprepare_imagewould have used (ZIPXL=9 / DEFAULT=15), so the bytes on the wire are identical to before — just computed later.Test plan
uv run pytest -q→ 439 passedruff check,ruff format,mypyclean🤖 Generated with Claude Code