Skip to content

⚡ Bolt: optimize ZRLE decoder performance - #16

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

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

Conversation

@kimocoder

Copy link
Copy Markdown
Owner

💡 What: Optimized the ZRLE (Remote Framebuffer encoding 16) decoder in ZrleDecoder.kt.

🎯 Why: The previous implementation suffered from several performance bottlenecks:

  • Frequent JNI transitions between JVM and native Inflater due to small buffer sizes.
  • Per-pixel coordinate arithmetic (division and modulo) in RLE decoding loops.
  • Per-rectangle object allocation for ZInput.
  • Redundant function calls for individual byte reads when decoding CPIXELs.

📊 Impact:

  • Faster UI rendering: Native Arrays.fill and elimination of division/modulo significantly speed up pixel filling for solid areas and RLE runs.
  • Lower CPU overhead: 16KB buffers reduce JNI overhead, and the readCpixel fast-path reduces branching and call stack depth.
  • Reduced GC pressure: Eliminates ZInput object allocation for every rectangle.

🔬 Measurement: Verified correctly using ./gradlew :app:testDebugUnitTest --tests "com.excp.podroid.x11.ZrleDecoderTest". All 6 functional and safety tests passed.


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

Optimized the ZRLE decoder by merging ZInput logic, increasing buffer sizes to 16KB to minimize JNI overhead, and refactoring RLE decoding loops to use incremental counters and bulk memory operations (Arrays.fill).

- Merge ZInput into ZrleDecoder to avoid per-rectangle allocation.
- Increase buffers to 16KB for better zlib decompression efficiency.
- Replace division/modulo with incremental counters in RLE loops.
- Use Arrays.fill for contiguous pixel runs.
- Implement fast-path for 3-byte CPIXEL reads.

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

This PR optimizes the ZRLE (RFB encoding 16) decode hot path by reducing inflater JNI overhead, removing per-rectangle helper allocations, and speeding up tile filling (especially for RLE/solid runs) to improve UI rendering performance.

Changes:

  • Increased zlib input/output buffers to 16KB and moved decompression state into ZrleDecoder (removing the per-rect ZInput wrapper/allocation).
  • Optimized solid and RLE tile decoding by using incremental row/col counters and Arrays.fill for contiguous pixel spans (avoids per-pixel div/mod).
  • Added a .jules/bolt.md note capturing the performance learnings and guidance.

Reviewed changes

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

File Description
app/src/main/java/com/excp/podroid/x11/ZrleDecoder.kt Reworks decompression buffering and optimizes tile decode loops (solid/RLE/cpixel reads) for performance and lower GC pressure.
.jules/bolt.md Adds internal documentation capturing the performance rationale and recommended patterns.

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

Comment on lines +52 to +53
// Decompressed output buffer (internal to ZInput logic).
private var zBuf = ByteArray(BUFFER_SIZE)
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