perf(images): render iTerm2 inline images in one sequence - #14
Open
paviro wants to merge 1 commit into
Open
Conversation
The graphics backend built images with ratatui-image's SlicedProtocol. For the iTerm2 protocol that slices the image into one PNG plus one OSC 1337 inline-image sequence per terminal row, so a fullscreen image emits dozens of encodes and sequences for the terminal to decode and place, which iTerm2 renders slowly. Slicing only matters for images that scroll partially in and out of view. The fullscreen viewer never scrolls an image, so switch to the non-sliced Protocol/Image widget: iTerm2 now gets a single whole-image OSC 1337, Kitty and Sixel keep their single transmission. The color-managed decode pipeline, worker builds, and cache are unchanged.
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.
Problem
Images render slowly in iTerm2. The cause is not protocol selection — the graphics backend already forces
ProtocolType::Iterm2in iTerm2. It's the encoding: images were built withratatui-image'sSlicedProtocol, which for the iTerm2 protocol slices the image into one PNG + one OSC 1337 inline-image sequence per terminal row. A ~50-row fullscreen image emits dozens of PNG encodes and inline-image sequences for the terminal to decode and place.Slicing only matters when an image scrolls partially in and out of view. The fullscreen image viewer never scrolls an image, so the slicing was pure overhead — paid only for
SignedPosition-based centering, which the plainImagewidget does just as well.Change
Switch the graphics path from
SlicedProtocol/SlicedImageto the non-slicedProtocol/Imagewidget acrossgraphics.rs,worker.rs, andmod.rs:Image::new(&proto)into a centered sub-Rect.The color-managed decode pipeline (EXIF, ICC→sRGB, viewport downscale cap), background worker builds, and cache are unchanged.
Verification
cargo buildclean, no warnings.cargo test --lib tui::imagepasses (7 tests).ESC ]1337;File=inline=1per image instead of one per row.