Knowing the size of the types in your program lets the compiler do a bunch of things:
- Allocate the correct amount of memory for stack frames (since all your local variables are on the stack).
- Allocate the correct amount of memory when heap-allocating a value.
- Reason about things in the type system regarding sized-ness.
Additionally, this is beside any optimizations that the compiler can do, for example: size_of::<Option<Box<usize>>>() == size_of::<Box<usize>>(), since a null pointer is an invalid bit pattern for Box and can therefore be used to represent None.
This doesn't really affect the size of your binary in any meaningful way. Chances are that the biggest thing which affects that is actual code rather than data. Technically, different types often have different instructions, so yes, different types could result in differently sized binaries, however any difference because of that is probably overshadowed by other things (such as generic monomorphization of functions).
At runtime, the size of your data does matter however. For example, 4 million u8s have the size of 4mb, however 4 million u128s have the size of 64mb.
However, knowing the size of the types in your program is simply part of compilation -- it's not something that can be turned off and is something that the compiler could not function without knowing.
-1? Also, it can enable to address hardware (in some circumstances).i128will produce a bigger binary thani32not because of the extra size of the numbers but because computers only have hardware that deals with 64 bits, so it must generate a lot more code for operations to manually handle the extra 64 bits without hardware support.