Possible bloat from over-use of default methods on trait objects #12449
Labels
I-compiletime
Issue: Problems and improvements with respect to compile times.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
I am not sure if this is an issue as such, but I figured that I ought to mention it.
I don't know the current linker behavior, but the best case is that all implementations of default methods for types that are coerced to trait objects must be generated and cannot be stripped because they are referenced by their vtable. As a result, there are a may be a number of method implementations that cannot be removed even if they do not happen to be used.
This is most notable for the
io::Writer
andio::Reader
traits, which are often used behind trait objects and have a number of default methods.Writer
has 28 default methods (not includingflush
andby_ref
), which is up to 513 methods over 19 implementations.Reader
has 31 default methods (not includingby_ref
andbytes
), which is up to 620 methods over 20 implementations.I do not mean to suggest that default methods should not be used for traits that are often uses as trait objects, but merely that some care should be used when adding them. In some cases things like such as wrapper structs, or the unpopular trait-just-to-add-methods may be appropriate.
The text was updated successfully, but these errors were encountered: