Skip to content

⚡ Bolt: Optimize ZrleDecoder performance - #17

Open
kimocoder wants to merge 1 commit into
kalifrom
bolt-zrle-optimization-3794014419376014781
Open

kimocoder wants to merge 1 commit into
kalifrom
bolt-zrle-optimization-3794014419376014781

Conversation

@kimocoder

Copy link
Copy Markdown
Owner

💡 What: Optimized ZRLE decoding by:

  • Increasing buffer sizes to 16KB to minimize JNI transition overhead.
  • Inlining ZInput to eliminate per-rectangle object allocation.
  • Fast-pathing readCpixel for direct buffer access.
  • Replacing expensive division/modulo in RLE loops with incremental counters.
  • Using java.util.Arrays.fill for bulk pixel operations.

🎯 Why: ZRLE decoding is a performance-critical path for X11/VNC rendering on mobile devices. The previous implementation had significant overhead from object allocations, small buffers, and expensive coordinate arithmetic in tight loops.

📊 Impact: Significant reduction in CPU usage during high-frequency screen updates. Use of native Arrays.fill and larger buffers improves throughput for dense updates.

🔬 Measurement: Run ./gradlew :app:testDebugUnitTest --tests "com.excp.podroid.x11.ZrleDecoderTest" to verify correctness. Performance can be observed during active X11 sessions.


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

Optimized ZRLE decoding by:
- Increasing buffer sizes to 16KB to minimize JNI transition overhead.
- Inlining ZInput to eliminate per-rectangle object allocation.
- Fast-pathing readCpixel for direct buffer access.
- Replacing expensive division/modulo in RLE loops with incremental counters.
- Using java.util.Arrays.fill for bulk pixel operations.

Co-authored-by: kimocoder <4252297+kimocoder@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 21:18
@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.

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

This PR optimizes the ZRLE (RFB encoding 16) decoder hot path to reduce per-rectangle overhead during X11/VNC rendering, primarily by reducing allocation, using larger buffers, and speeding up RLE pixel writes.

Changes:

  • Increased compressed/decompressed buffering and inlined the previous inflater wrapper into ZrleDecoder for fewer allocations and fewer small reads.
  • Added a fast-path for readCpixel() when the decompressed buffer already has enough bytes.
  • Reworked plain/palette RLE loops to avoid division/modulo and use java.util.Arrays.fill for bulk pixel spans.

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 Inlines inflater output handling, increases buffer sizes, and optimizes RLE/pixel write loops for throughput.
.jules/bolt.md Adds a Bolt/Jules note documenting the performance motivations and optimization guidelines used for this change.

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


// Wrap the inflater so tile-level code just calls readByte()/readBytes().
val zi = ZInput(inflater)
zPos = 0
Comment on lines 175 to 179
while (filled < total) {
val color = zi.readCpixel()
val runLen = zi.readRunLength()
val color = readCpixel()
var runLen = readRunLength()
if (filled + runLen > total) throw IOException("ZRLE: plain RLE run overruns tile ($filled+$runLen > $total)")
repeat(runLen) {
val pos = filled + it
val row = pos / tw; val col = pos % tw
target[(ty + row) * stride + (tx + col)] = color
}
filled += runLen
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