Optimize tile storage by preventing saving of fully transparent images. #2101
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.
I manage Redstoner Maps, which hosts Overviewer renders of 9 worlds, each featuring two tile sets: the standard "Overworld" render and a customized cave render named "Underworld". These 18 tile sets collectively held a staggering 22,681,416 files. While this quantity was warranted given the expansive nature of some of the worlds, it posed logistical challenges during a server migration. Consequently, I took a look at Overviewer to identify optimizations capable of reducing the file count without compromising the final map quality.
Across worlds such as BigPlots, Creative, and Trusted on Redstoner Maps, the Underworld tile sets contain vast regions of complete transparency. These areas were represented by individual transparent tiles generated by Overviewer. Furthermore, I observed that navigating beyond the rendered areas prompted Leaflet to request "blank.png" in response to expected 404 errors, effectively serving as a placeholder for missing tiles.
Building upon this existing functionality, this pull request proposes a straightforward yet effective adjustment: introducing a check during rendering to determine whether tiles are entirely transparent before saving them to disk. Tiles identified as fully transparent are excluded from the saving process.
Upon implementing this pull request, I regenerated all 18 tile sets on Redstoner Maps. The resultant file count went from 22,681,416 to a combined total of 8,184,222 files, marking a substantial ~64% reduction. While 8 million files remains considerable, this reduction notably eased the burden on inode usage and simplified data transfer processes for me. Most importantly, this optimization does not compromise the final product; missing tiles are seamlessly replaced with "blank.png" by Leaflet.
This pull request primarily benefits users of the cave renderer, especially on worlds with sparse cave systems, as they are the most likely to contain fully transparent tiles. Most normal renders will not experience significant benefits from this optimization.