-
Dead Code Elimination (DCE) Isn't Perfect (or happens late):
- Ideal Scenario: You'd expect the compiler's DCE pass to recognize that the
Deserialize
implementations generated by the derive macro are never called and completely eliminate them from the final binary anyway. If DCE worked perfectly and early, removing the derive manually shouldn't change the size much, as the code was already being discarded. - Reality: The analysis for DCE, especially across crates and with complex features like generics and macros (which
serde
uses heavily), can be intricate. Sometimes, code might appear reachable during earlier compilation stages or might have subtle linkages that prevent easy removal until LTO.
- Ideal Scenario: You'd expect the compiler's DCE pass to recognize that the
-
The Butterfly Effect of Optimization Heuristics:
- Compilers use complex heuristics to decide how to optimize code: when to inline functions, how to allocate registers, how to arrange code blocks for cache efficiency, etc.
- Removing the
#[derive(Deserialize)]
cha