Note that most operating systems do not always store all code in memory. Since the code is persistent, the OS can always load it from a file on demand, as it will load dynamic data from swap. But this does not mean that unused code is never loaded, since the OS does not load it with individual methods, but with pages. In other words, it is very difficult to predict which parts of your code segment actually go into memory unless you have very deep knowledge about your OS and the structure of the code segment. The only thing that can be said for sure is that it is possible that your code consumes less physical memory than its actual size.
Regarding the speed of execution, I do not think the answer. This can increase the download speed of the application, but when the code is executed, no one cares about how big it is, and it absolutely does not affect the speed. That is, if you do not come close to your memory limit, and the OS starts to change a lot, and everything becomes very slow.
As already mentioned, the compiler can optimize your code. But you can also do this yourself using #ifdefs for your debugging methods, and this is usually recommended.
source share