实体框架spinup在x64 vs x86上慢得多 [英] Entity Framework spinup much slower on x64 vs x86

查看:226
本文介绍了实体框架spinup在x64 vs x86上慢得多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动时间即使是微小的DbContext 。



在采取他的代码并将其移动到单独的解决方案以尽可能隔离之后,我发现包含项目的平台目标对EF启动过程的运行时间有深刻的影响。



当定位x64时,我看到测试需要大约7秒钟来启动第一个DbContext和< 1秒旋转第二个DbContext(符合我的同事的发现谁也是针对x64)。然而,当我将平台目标切换到x86时,第一个DbContext启动时间减少了约4秒,达到3.34633秒,而第二个DbContext与x64的时间相同。



鉴于此,当针对64位系统与32位系统时,实体框架似乎正在经历一个非常不同的初始化过程。有没有人有任何洞察力来解释这个问题?

解决方案

这个问题是完全可重复的。我刚刚运行它,并使用dotTrace性能分析器来收集x86和x64执行的快照。我报告的时间大致相同。但x64和x86跟踪之间确实没有明显区别,除了x64至少需要两倍于x86的时间。



但是,这是跟踪NUnit测试运行。通过运行相同的测试,就像控制台应用程序一样,我得到这样的时间:

  x86:0,6864012,0,0468001 
x64:1,0608019,0,0468001

看起来好多了,不是吗? x86和x64之间仍然存在差异,但对于某些操作,x64代码通常可能较慢。



此时的问题不在于EF,而是关于NUnit及其



编辑:



我做了更多的测试。 NUnit和Resharper的任务运行程序都有这个问题,但它只影响第一个测试。所有其他测试都很快运行。 xUnit显示相同的行为。


My coworker posted this question yesterday: 7-second EF startup time even for tiny DbContext.

After taking his code and moving it to a separate solution to isolate it as much as possible, I found that the containing project's platform target had a profound affect on the runtime of the EF startup process.

When targeting x64, I saw that the test took ~7 seconds to spin up the first DbContext and <1 second to spin up the second DbContext (consistent with my coworker's findings who is also targeting x64). However when I switched the platform target to x86, the first DbContext spin up time was reduced by about 4 seconds down to 3.34633 seconds while the second DbContext took the same amount of time as the x64 case.

Given this, it appears the Entity Framework is going through a much different initialization process when targeting a 64-bit system vs 32-bit system. Does anyone have any insight into what is going on under the hood to explain this?

解决方案

The issue is fully reproducible. I have just run it and used dotTrace Performance profiler to collect snapshots for both x86 and x64 executions. I got mostly same times as you report. But there is really no obvious difference between x64 and x86 traces - except the x64 takes at least twice the time of x86 everywhere.

But that was tracing of NUnit test run. By running the same test just as console applications I get times like this:

x86: 0,6864012, 0,0468001
x64: 1,0608019, 0,0468001

That looks much better, doesn't it? There is still difference between x86 and x64 but the x64 code can be slower in general for some operations.

The problem at this point is not about EF but about NUnit and its test runner.

Edit:

I did some more testing. Both NUnit's and Resharper's task runner has this issue but it affects only the very first test. All other tests run quickly. xUnit shows the same behavior.

这篇关于实体框架spinup在x64 vs x86上慢得多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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