Skip to content

Make load_from_memory generic to improve compile times #2470

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fintelia
Copy link
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
Copy link
Member

197g commented May 24, 2025

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

Copy link
Member

@197g 197g left a comment

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).

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