Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
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
ZrleDecoderfor 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.fillfor 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 |
| 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 |
💡 What: Optimized ZRLE decoding by:
ZInputto eliminate per-rectangle object allocation.readCpixelfor direct buffer access.java.util.Arrays.fillfor 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.filland 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