Skip to content
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

Add note about monomorphisation #24

Open
marcospb19 opened this issue Apr 17, 2021 · 6 comments
Open

Add note about monomorphisation #24

marcospb19 opened this issue Apr 17, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@marcospb19
Copy link

Generics with static dispatch can lead to duplicated functions, and if they are big enough, it will make for a large piece of the final binary.

Alternatives are dynamic dispatch with dyn, or just removing generic code.

Is seems very important for minimizing binary size.

(If you don't want to change the function API, and the function is being generic over something like AsRef<Path>, you can also create helper function which resolves path.as_ref() and calls a non-generic function that receives &Path instead.)

@johnthagen
Copy link
Owner

This is a good idea.

Ideally, what I'd like is if we could gather some references to some quantitative research on the relationship between monomophisation and binary size.

If anyone in the community would be willing to look for/watch for such articles and post them to this issue, that would be great!

@johnthagen johnthagen added the enhancement New feature or request label Apr 29, 2021
@frencojobs
Copy link

@jonhoo did a video about monomorphisation just today. It is really well explained, should consider it as one of the reference contents.

@johnthagen
Copy link
Owner

@jonhoo did a video about monomorphisation just today. It is really well explained, should consider it as one of the reference contents.

@frencojobs Thanks for this link, @jonhoo's content is great. Since it's a little more general, I think it's out of scope for min-sized-rust, but I'm glad it's linked in this issue for more people to find to learn from.

@Artoria2e5
Copy link

Artoria2e5 commented Aug 6, 2021

It might also be useful to link to https://github.com/llogiq/momo, a proc_macro that makes monomorphisation (Into, AsRef, AsMut) helper functions for you.

twiggy seems to provide a functionality for analyzing monomorph code size bloat. https://rustwasm.github.io/twiggy/concepts/generic-functions-and-monomorphization.html (You could do that with hand-made tools downstream of cargo bloat output too.)

@johnthagen
Copy link
Owner

@Artoria2e5 Thanks for this. Both of those tools are great additions. I've added them in #31

@johnthagen
Copy link
Owner

A reference related to this topic was added in c4be196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants