Format/size detection performance improvements #247
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.
Adds fast, lua-based format detection and dimension reading for common image formats, falling back to ImageMagick when needed. This avoids spawning external processes for basic operations, making things noticeably snappier, especially when using image.nvim's API from other plugins (my use-case).
The lua implementations are significantly faster but slightly less forgiving with malformed files compared to ImageMagick. We fall back to the existing methods when lua-based parsing fails, so everything should be backward compatible. More test images might be beneficial, especially for heic/avif formats.
Benchmarking the time to run
from_image
:magick_rock
:283.36ms
0.50ms
4.96ms
0.36ms
magick_cli
:294.32ms
0.48ms
32.82ms
0.16ms
Similar speedups for other formats.
Note: most of the logic in
dimensions.lua
was generated with Anthropic's Claude.