Does `#[derive(Debug)]` increase binary size?

Hi, I've read some comments about the #[derive(Debug)], says it increases the code size and binary size, especially the "release" profile. Is it true?

If yes, can I replace all derive(Debug) with impl std::fmt::Display? Since I think I still need to print the structure for debugging.

If your Debug implementations are not used somewhere, then they will not be included in the binary. So, if deleting them does not cause a compilation error, then they would have been discarded automatically anyway.

Whether you derive or impl the trait, and whether the trait is Display or Debug, doesn't make any difference to this principle.

3 Likes

Thanks for your sharing!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.