我们在Form上的Load事件处理程序中构建了29个用户控件(每个控件包含许多其他标准和用户控件)。
禁用优化(在调试模式下或在发布模式下的高级编译器设置内),大约需要7秒。启用优化后,大约需要50秒。这只发生在我们的一台非互联网连接的实验室机器上;我的机器上的启动时间或发布和调试大致相同。我们从Visual Studio 2015开始定位.NET Framework 4.5 x64。
使用远程调试器并定期暂停,看起来这是由JIT在代码实例化每个用户控件之前使用大量CPU时间引起的。可能导致这种情况的任何想法?
JIT函数的堆栈跟踪似乎占用了大部分时间:
clrjit.dll!THX_NColBestCoverage(struct tagNCOLLIFETIME *,struct tagNCOLREGION *,class hashBv *,unsigned int,unsigned int,int *,struct CI_TAG *)
clrjit.dll!THX_NColDeterminePhysregAvail(struct tagNCOLLIFETIME *,struct tagNCOLREGION *,class hashBv *,unsigned int,unsigned int,struct tagSYM *,int *,int *,struct CI_TAG *)
clrjit.dll!THX_NColProcessCandidateRegion(struct tagNCOLLIFETIME *,struct tagNCOLREGION *,struct tagNCOLREGION *,struct tagNCOLUSEBENEFITS *,struct tagTUPLE *,int,struct tagNCOLPHYSREGAVAILS *,struct CI_TAG *)
clrjit.dll!THX_NColor(struct tagFUNC *,struct CI_TAG *)
clrjit.dll!THX_dop2_CodegenUpdate(struct tagFUNC *,struct CI_TAG *)
clrjit.dll!THX_dop2(class JitContext *,struct CI_TAG *,unsigned char * *,unsigned int *)
clrjit.dll!PreJit::compileMethod(class ICorJitInfo *,struct CORINFO_METHOD_INFO *,unsigned int,unsigned char * *,unsigned long *)
[Managed to Native Transition]
答案 0 :(得分:0)
对不起,我对你的实际问题有点困惑。您是否在试图找出使用优化器时需要更长时间的原因?
如果是这样,我的答案是优化器正在占用CPU(如你所说),因为它必须优化每个信息和数据被推入和推出应用程序,甚至是看似少量的代码,你必须记住,如果你调用或加载某些东西,无论是一个函数还是从其他地方调用另一个对象,它必须尽可能地使它工作。而不是在运行时作为对象/函数/无论需要做什么,它只是在你甚至可以使用任何东西之前优化所有这些。