Open marcospb19 opened 3 years ago
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!
@jonhoo did a video about monomorphisation just today. It is really well explained, should consider it as one of the reference contents.
@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.
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.)
@Artoria2e5 Thanks for this. Both of those tools are great additions. I've added them in #31
A reference related to this topic was added in c4be196
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 resolvespath.as_ref()
and calls a non-generic function that receives&Path
instead.)