Performance optimizations + abstraction #27
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.
Hopefully this is not too much stuff.
Changes
draw_direct
into 4 functions:kitty_encode
,kitty_encode_chunked
,kitty_encode_compressed
, andkitty_encode_chunked_compressed
. Now it's possible to choose whether to use compression and chunking. All of these take anIO
to write the image data to.draw_direct
now callskitty_encode_chunked
withstdout
.Benchmarks
On my machine using the mandril from TestImages (not counting the time to load the test image)
Original code
draw_direct
:0.194233 seconds (8.37 k allocations: 8.906 MiB, 2.58% gc time)
RGB
kitty_encode
:0.020691 seconds (37 allocations: 779.992 KiB)
chunked
:0.022022 seconds (823 allocations: 816.617 KiB)
compressed
:0.080171 seconds (75 allocations: 1.063 MiB)
chunked_compressed
:0.075660 seconds (1.28 k allocations: 3.546 MiB)
RGBA
kitty_encode
:0.033826 seconds (77 allocations: 1.047 MiB)
chunked
:0.049188 seconds (1.48 k allocations: 1.108 MiB)
compressed
:0.104464 seconds (78 allocations: 1.316 MiB)
chunked_compressed
:0.132745 seconds (1.28 k allocations: 3.796 MiB)
I realized that if we make an interface similar to the one in Sixel.jl, it'll be possible to integrate this with ImageInTerminal.jl pretty easily. Maybe in the future things can be organized such that ImageInTerminal only handles the displaying logic and each image format package only handles reading and writing for their own format. Having a package that works for every terminal image format would be cool.