Skip to content

Make load_from_memory generic to improve compile times - #2470

Merged
197g merged 4 commits into
image-rs:mainfrom
fintelia:load-from-memory-generic
Jun 6, 2025
Merged

197g merged 4 commits into
image-rs:mainfrom
fintelia:load-from-memory-generic

Conversation

@fintelia

Copy link
Copy Markdown
Contributor

Currently, the load_from_memory[_with_format] methods cause rustc to generate code for them when compiling the image crate, even if downstream code never decodes images from in-memory buffers. This PR changes them to be generic so that they only get monomorphized only if they are actually used.

Reduces time for release builds by ~1.2 seconds on my machine.

See also: #2468, #2469

@197g

197g commented May 24, 2025

Copy link
Copy Markdown
Member

I didn't realize load_from_memory_with_format was so heavy on compiletime, 1.2 seconds is a lot. Nice find.

@197g 197g left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you add some comment that documents the reason for the generic? It would be nice to have at least some resistance to regressing. (Also I'm a little curious as to why the compile time cost is that large…, it would seem to be just a bit of codegen, but probably also affects the number of linked items dramatically).

@197g
197g merged commit 56898e0 into image-rs:main Jun 6, 2025
@fintelia
fintelia deleted the load-from-memory-generic branch June 6, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants