Store raw image data as LZ4 compressed blobs #69
Merged
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.
Resolves #45
(Well not quite, but it's a considerable improvement for now)
This PR changes the raw image data to be stored as LZ4 Frame Format blobs. LZ4 because it's got very fast compression/decompression speeds and the frame format because
lz4_flex
's block format stores the output in aVec
allocated for the maximum possible output size which leads to a pretty large memory spike. Granted Linux (and Mac?) typically doesn't allocated zero'd pages until they're actually used for something else, but I figured the lower memory spike was worth the extra code complexity to handle streamingDemo
demo.mp4
Profiles
main
This PR
Analysis
Above you can see that with this PR scrolling over all of
bun
's README is typically a steady ~20 MiB of RAM with two spikes. One towards the beginning from loading the ~55 MiB RGBA8 data before compressing it into an LZ4 blob, and a second towards the end when that blob is decompressed to get renderedThe peak memory usage is a bit lower now since the raw image data generally going to be loaded and dropped at different times. This would cause a much larger difference on a file that has more uniform sizes whereas
bun
's README has a single outlier