Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effect of unused methods and properties on library or executable

I'm playing around with creating a source code generator for C# (.NET). Will generating properties or methods that never get called cause my code to run slower? How about inserting "using" statements for libraries that don't get used?

I'm assuming the compiler is smart enough not to build in the unused "using" statements, but there is no way for it to know about properties and methods since they could be inserted for external applications to use.

like image 380
Rick Avatar asked Jan 22 '10 20:01

Rick


1 Answers

The compiler is already smart enough to only list referenced assemblies in the final executable that are actually used. No need to fiddle with assembly references or using directives.

The JIT compiler will only ever generate code for methods that are actually called. So you will not have any machine code or compile time overhead due to code that is never used.

Your executable image is getting referenced through a memory-mapped file by the CLR. RAM will only be used if actual content in the DLL is used by the CLR. It depends how the IL of the methods you use is distributed through the image. There are reasonable odds that since the JIT compiler never references the IL, the image data won't be paged into RAM either. In other words, you'll lose some virtual memory space but won't consume a corresponding amount of RAM.

If your DLL is strong named and stored in a non-trusted location then the warm boot time will be slightly longer due to the larger file size.

like image 75
Hans Passant Avatar answered Oct 13 '22 19:10

Hans Passant