-
Notifications
You must be signed in to change notification settings - Fork 10
Add load_meta for faster metadata, improve DMI field handling, parsing optimizations
#23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
load_meta for reading only IHDR and zTXtload_meta for reading only IHDR and zTXt, better DMI field handling
load_meta for reading only IHDR and zTXt, better DMI field handlingload_meta for reading only IHDR and zTXt, better DMI field handling, parsing optimizations
load_meta for reading only IHDR and zTXt, better DMI field handling, parsing optimizationsload_meta for faster metadata, improve DMI field handling, parsing optimizations
…buffer() for preallocation
ZeWaka
reviewed
Aug 13, 2025
ZeWaka
approved these changes
Aug 23, 2025
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.
Breaking Changes
(minor) breaking API change,
Icon::loadnow requiresRead + Seekrather than justReadto be implemented on its reader.BufReaderandFileboth implementSeek, though, so it's unlikely anything will have an issue with this.Changes
load_meta
Icon::loadspends a lot of time callingimage::load_from_memory_with_formatand parsing IDAT chunks.This PR adds
Icon::load_metaandRawDmi::load_meta, which skip over any chunks that aren't the PNG header, IHDR, or zTXt. This makes it suitable for pure metadata (e.g. only reading the icon states, width, height, or DMI version) without spending any time doing image data parsing.Direct PNG Decoding
By converting from
image::load_from_memory_with_formatto a raw buffer decode withPngDecoder, the MTPC ofIcon::loadis reduced from 32.447ms to 21.175ms, making it significantly faster. The major savings are incrop_immcalls, which are now directly loaded from decoded PNG data by indexing, which is significantly faster.DMI Handling Improvements
looping = 0was found in at least one DMI I tested (I tested this on every BeeStation dmi file in the repository) so I made it correctly convert this toIndefinitelyIt also appears a decent volume of DMIs did not have a width or height, so I made them optional fields and they default to 32x32 because that appears to be what BYOND does.
Fixes icon states that have names containing quotes or backslashes being parsed incorrectly. They will now be loaded and saved with escape characters handled automatically.
Also satisfies clippy by converting format strings to use templating. help.
Performance
As you can see here almost all of
load's time is spent doing image parsing. We can just skip this!Here's
loadafter replacing the PNG decoder.Here's
load_metaafter replacing split_terminator with parse_dmi_line (I'm pretty sure it's almost faster despite handling quite a few more cases)
You can see that
load_metais ~75x faster (particularly for large icon files, smaller files it's only about 10x faster):Testing
I tested this on literally every image on TG and Bee, and it can load them just fine. I also added additional test images to cover edge cases (greyscale + alpha icons, extremely small icons that are well compressed)