Screenshot Viewer

Screenshot Viewer

1M Downloads

[Feature request] Caching screenshots

BakinDP opened this issue ยท 5 comments

commented

Most of the times I open Screenshot Viewer to quickly check or delete fresh screenshots, but as it seems that there is no caching of images, it takes a lot of time to load existing screenshots (more than the mod is actually being used in my case).

Checking for existing files is computationally light task, so instead of initially loading full size images it might be better to call loading smaller thumbnails beforehand generated by mod and only after full size (or on player's input for each image).

The option to disable or choose the amount of compression (1/2, 1/4 etc) would also be very nice!

Thank you!

commented

For a little more context, I have an OC Ryzen 9 5950X, 24Gb RAM dedicated and PCIe 3.0 NVME TLC SSD. The game runs Fabric 1.20.1 with all most popular optimization mods. Actual for the latest release of Screenshot Viewer.

commented

Hello,
Thank you for your feedback. When you say "It takes a lot of time to load existing screenshots" ; are you saying that there's a lag when opening the screen? Or that the images take a long time to load? Or maybe just the fact that loading all screenshots are inefficient?
If you experience any real issue, maybe you can send a quick video just so I have better insight into what's going on. I've tried replicating such issues with a high number of images, and it all seemed to load perfectly, maybe it's due to my graphics card, being a RTX 2060.

Regarding your suggestion for thumbnails, it might not be such a good idea. Minecraft uses the library STB_image in order to load images into the game, and Screenshot Viewer uses it too. And from what I know, there's no method to load any thumbnail/compressed subimage of an image in this library, meaning that an implementation of such a feature would require loading the full size image, compressing it, and caching the compressed version, which requires a lot of operations for a screen that must be reloaded every time it is opened. Screenshot images load asynchronously, and are cached for the whole duration the Manage Screenshots screen is open. That's why I'm pretty skeptical about adding this feature. I'm not convinced it would really perform better.

I'd like to hear your thoughts about this. Have a nice day!

commented

Thanks for the reply!

There is a lag (stutter), not a huge problem, and a delay on loading and therefore accessing images, which is actually important.
https://github.com/LGatodu47/ScreenshotViewer/assets/74774853/f09b3d13-9606-458e-8b3d-9ef211cca102

My idea is to implement scanning through screenshots folder in minecraft (I'll call it 'source') and comparing existing images with contents of folder with thumbnails ('preview'), which is initially created and empty on first boot with mod.
If the image from source is not detected in preview (by name, for example), then the mod will process one-time compression and saving of this image to preview, then load the image to widget directly from compression buffer. Later, the general reading function (could't find it) will detect existing thumbnails and call general loading function (this too) with thumbnail's path instead of full-size image, so the getImage(screenshotFile) gets a thumbnail's contents.

Once thumbnails are loaded, the other part of mod will begin loading full-size images and open them on user click, just as it does now.

As the situation of thumbnail not representing the original image is rare due to how minecraft saves them, it still would be nice to have a button to repeat the process of compression for each image individually or the entire folder.

I understand that this method may not help with the initial delay (when screenshots are completely empty) or even worsen it by a bit with extra computations, but it definitely should help with faster finishing of IO work and closing threads especially with highres images.

commented

Hi,

Did some benchmarking and some more research about what you were speaking about with image compression and it can indeed speed up loading times by a significant amount (in fact during my tests I noticed the loading time is exponentially faster the lower the resolution is). So I'll probably fork the main branch in order to work on this feature for the next version of the mod. I think I would leave it optional, because it implies creating "temporary" thumbnail files, which might take space on the user's computer without him knowing about it.

Oh and I figured out why there was a little lag for loading images, it's because you're sorting your screenshots by descending order, and the bug is that it's loading the screenshots in ascending order. I'm pretty sure this will be fixed in the next version (if I don't forget about it).

commented

So glad to hear that! Thank you for your work!