实体框架在 x64 和 x86 上的启动速度要慢得多 [英] Entity Framework spinup much slower on x64 vs x86

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

问题描述

我的同事昨天发布了这个问题:7-second EF即使对于很小的 DbContext 也需要启动时间.

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

在获取他的代码并将其移至单独的解决方案以尽可能将其隔离后,我发现包含项目的平台目标对 EF 启动过程的运行时产生了深远的影响.

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.

当以 x64 为目标时,我看到测试花费了大约 7 秒来启动第一个 DbContext,并且需要 <1 秒来启动第二个 DbContext(与我的同事的发现一致,他也以 x64 为目标).然而,当我将平台目标切换到 x86 时,第一个 DbContext 启动时间减少了大约 4 秒,降至 3.34633 秒,而第二个 DbContext 花费的时间与 x64 情况相同.

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.

鉴于此,当面向 64 位系统与 32 位系统时,实体框架似乎正在经历一个截然不同的初始化过程.有没有人对幕后发生的事情有任何见解来解释这一点?

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?

推荐答案

该问题是完全可重现的.我刚刚运行它并使用 dotTrace Performance profiler 收集 x86 和 x64 执行的快照.我和你报告的次数大致相同.但是 x64 和 x86 跟踪之间确实没有明显区别——除了 x64 在任何地方都至少花费 x86 的两倍时间.

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.

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

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

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

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.

此时的问题不在于 EF,而在于 NUnit 及其测试运行器.

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

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

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.

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

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