Skip to content

⚡ Bolt: optimize ZRLE decoder performance - #24

Open
kimocoder wants to merge 1 commit into
kalifrom
bolt-optimize-zrle-decoder-2593770975122726470
Open

kimocoder wants to merge 1 commit into
kalifrom
bolt-optimize-zrle-decoder-2593770975122726470

Conversation

@kimocoder

Copy link
Copy Markdown
Owner

💡 What:

  • Increased inputScratch and ZInput.buf to 16KB to minimize JNI transition overhead during zlib decompression.
  • Removed unused outputBuf property.
  • Implemented a fast-path in readCpixel() that reads 3 bytes directly from the buffer when available, bypassing redundant checks.
  • Refactored Solid, Plain RLE, and Palette RLE decoding loops to use java.util.Arrays.fill for horizontal pixel spans and replaced coordinate arithmetic (division/modulo) with manual tracking.

🎯 Why:

  • Graphics decoding is a hot path in Podroid. Small buffers and frequent JNI calls significantly throttle decompression speed.
  • Integer division and modulo are relatively expensive on mobile ARM CPUs; eliminating them in loops that run millions of times per second provides a measurable boost.
  • Arrays.fill typically maps to optimized native memset or SIMD instructions, which are much faster than per-pixel manual assignment.

📊 Impact:

  • Faster X11 screen updates, especially during high-motion or large-area redraws.
  • Reduced CPU consumption during VNC session rendering.

🔬 Measurement:

  • Verified correctness by running ./gradlew :app:testDebugUnitTest --tests "com.excp.podroid.x11.ZrleDecoderTest".

PR created automatically by Jules for task 2593770975122726470 started by @kimocoder

- Increase input and decompression buffers to 16KB to reduce JNI overhead.
- Remove unused outputBuf property.
- Implement readCpixel fast-path for direct 3-byte reads from internal buffer.
- Refactor RLE decoding loops to use Arrays.fill and avoid division/modulo.

Co-authored-by: kimocoder <4252297+kimocoder@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 24, 2026 21:07
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Optimizes the ZRLE (RFB encoding 16) decoding hot path to reduce per-pixel overhead during VNC/X11 framebuffer updates.

Changes:

  • Increased zlib input/output buffering to 16KB and removed an unused buffer field.
  • Optimized Solid / Plain RLE / Palette RLE tile decoding by replacing per-pixel loops (and div/mod) with span fills and manual coordinate tracking.
  • Added a fast-path in readCpixel() to read 3 bytes directly when already buffered.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/src/main/java/com/excp/podroid/x11/ZrleDecoder.kt Performance-focused refactor: larger buffers, Arrays.fill spans, div/mod elimination, and CPIXEL fast-path.
.jules/bolt.md Documents the performance learnings and standardization goal behind the optimization approach.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 241 to 243
private inner class ZInput(private val inf: Inflater) {
private val buf = ByteArray(256)
private val buf = ByteArray(16384)
private var pos = 0
Comment on lines 46 to 48
// Scratch buffer for compressed input read from the socket.
private var inputScratch = ByteArray(4096)
// Decompressed output buffer; re-used across inflate calls within one decode() call.
private var outputBuf = ByteArray(4096)
private var inputScratch = ByteArray(16384)

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