简体   繁体   English

实体框架4与实体框架3.5的表现如何?

[英]How is the performance of entity framework 4 vs entity framework 3.5?

I have one query on my page that takes at least a half second to execute using EF 3.5. 我的页面上有一个查询,使用EF 3.5执行至少需要半秒钟。 When I used a stored procedure the speed was noticably faster. 当我使用存储过程时,速度明显加快。 It is a very complex query. 这是一个非常复杂的查询。 Will there be any performance improvements in the upcoming EF 4.0? 即将到来的EF 4.0会有任何性能改进吗? And does EF 4.0 really beat out 3.5 performance wise? EF 4.0真的击败了3.5性能吗?

The short answer is it's too early to tell. 简短的回答是现在判断还为时过早。 The .Net guys are focusing almost entirely on performance until the release on April 12th has to be finalized and localized. .Net的人几乎完全专注于性能,直到4月12日的发布必须最终确定和本地化。 Also, what is meant by faster? 还有什么意思更快? Faster can be viewed in many ways, for example: 可以通过多种方式查看更快,例如:

  • Entity Framework 4.0 has new features , the object tracking improvements alone may mean huge wins since you're not doing that manual work yourself...in any case, at least the development's faster. 实体框架4.0具有新功能 ,单独的对象跟踪改进可能意味着巨大的胜利,因为你自己没有做过手工工作......无论如何,至少开发速度更快。
  • If it didn't work at all before, lighter weight objects with POCO support may mean a lot less memory being shifted when dealing with lots of objects as well. 如果它之前根本不起作用,那么具有POCO 支持的较轻重物可能意味着在处理大量物体时移动的内存也会少得多。 No matter how small the cost of extra properties being populated when fetching from the DB, there is a cost both in instantiating and tracking them (load time and memory consumption). 无论从数据库获取时填充的额外属性的成本有多小,实例化和跟踪它们(加载时间和内存消耗)都会产生成本。

In your specific case, a half second is a long time for anything but a very complex or high volume query...have you looked to see how much time is spent in the database and how much time is spent once .Net has the data? 在你的具体情况下,除了非常复杂或高容量的查询之外,半秒是很长的时间......你是否想看看在数据库中花了多少时间以及花了多少时间.Net有数据? If you're spending most of your time outside of SQL then yes, the base improvements in reflections in Net 4.0 should provide you some speed improvement...however if you're spending all your time in SQL, it won't help much at all. 如果你把大部分时间花在SQL之外,那么是的,Net 4.0中反射的基础改进应该会为你提供一些速度提升......但是如果你把所有时间花在SQL上,它将无济于事一点都不 The bulk of your performance problem may be indexing of the generated SQL and not Entity Framework hydration performance. 您的性能问题的大部分可能是生成的SQL的索引,而不是实体框架的水合性能。

I would follow Kane's comment, look at the SQL it's generating for your query, is it possible for you to post this and the stored procedure that is quick so we can maybe find where the problem lies? 我会按照凯恩的评论,看看它生成查询的SQL,才有可能为您发布此,那就是快速的存储过程,所以我们也许可以找到问题所在?

From the ADO.NET blog : 来自ADO.NET博客

Customizing Queries – Adding support for existing LINQ operators, recognizing a larger set of patterns with LINQ, writing model defined functions along with the ability to use these in LINQ, and a number of other ways to create and customize queries. 自定义查询 - 添加对现有LINQ运算符的支持,使用LINQ识别更大的模式集,编写模型定义的函数以及在LINQ中使用这些函数的能力,以及许多其他方法来创建和自定义查询。

SQL Generation Readability Improvements – Improving the readability, along with TSQL performance optimizations, of the generated queries to make it much easier to understand what is happening SQL生成可读性改进 - 提高生成查询的可读性以及TSQL性能优化,使其更容易理解发生的情况

So these two points imply you could see improvements in the way it's generating your query from LINQ. 因此,这两点意味着您可以看到它从LINQ生成查询的方式有所改进。

However it's unlikely that an ORM will ever be able to out-perform a query you've written from scratch as it has to cater for so many different scenarios, and usually the most common one is defaulted to. 但是,ORM不太可能超出您从头开始编写的查询,因为它必须满足这么多不同的场景,通常最常见的是默认情况。 EF 3.5 seemed to produce some very efficient join SQL when I used it, probably the best I've seen from an ORM so there is hope you can ditch the SP in 4.0. 当我使用它时,EF 3.5似乎产生了一些非常有效的连接SQL,这可能是我从ORM中看到的最好的,所以希望你可以放弃4.0中的SP。

If you've got a stored procedure I'm guessing it's a big query - sending this SQL text each time to the server will cause a lot of network traffic which is one other thing you may or may not have considered. 如果你有一个存储过程,我猜这是一个大问题 - 每次向服务器发送这个SQL文本都会导致很多网络流量,这是你可能或可能没有考虑过的另一件事。 Obviously on the same server or inside the same internal network this a 'cutting your hair to lose weight' style optimisation. 显然,在同一台服务器上或同一内部网络内,这是一种“减少头发减肥”的风格优化。

When it comes to really complex queries, I've not seen any evidence that any of L2S, NH, or EF can generate a better query plan than I can in a sproc. 当涉及到非常复杂的查询时,我没有看到任何证据表明L2S,NH或EF中的任何一个都可以生成比我在sproc中更好的查询计划。 I love ORM's (especially NH), but there are still times when ORM execution time can get curbstomped by a well written sproc . 我喜欢ORM(特别是NH),但是有时ORM执行时间可以通过编写良好的sproc来实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM