在库或可执行文件未使用方法和性能的影响 [英] Effect of unused methods and properties on library or executable

查看:94
本文介绍了在库或可执行文件未使用方法和性能的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有创造的源泉code生成的C#(.NET)玩耍。将生成的属性或方法,从来没有得到所谓的事业我的code运行速度变慢?如何加入使用不习惯于对图书馆的语句?

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.

推荐答案

编译器已经是足够聪明,只列出引用的程序集在决赛中的可执行文件,实际使用。无需摆弄集引用或使用指令。

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.

JIT编译器将只产生code为实际调用的方法。所以你不会有任何机器code或编译时的开销,由于code表示从未使用过。

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.

您的可执行映像是越来越通过CLR的内存映射文件中引用。如果在DLL实际内容被用于由CLR RAM将只被使用。这取决于如何使用方法的IL通过图像分发。有合理的可能性,由于JIT编译器从未引用的IL,图象数据将不被任一寻呼到RAM中。换句话说,你会失去一些虚拟内存空间,但不会消耗内存的相应金额。

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.

如果您的DLL强命名并保存在一个不受信任的位置,然后在热启动时间会稍长,由于较大的文件大小。

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.

这篇关于在库或可执行文件未使用方法和性能的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆