<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx</link><description>Over the past few weeks the EF team has been putting together a whitepaper that talks about the performance considerations developers should take when using Entity Framework. Performance is one critical aspect of developing modern applications, and this</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10294289</link><pubDate>Mon, 16 Apr 2012 22:39:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10294289</guid><dc:creator>Diego B Vega</dc:creator><description>&lt;p&gt;@cynic: I don&amp;#39;t have any information on whether .NET 4.5 will work in Windows XP, but I can tell you that we are planning to make EF more independent of the version of .NET in the future, so that hopefully we will get to a point in which we will be able to release a version of EF that is compatible with .NET 4.0 but has these perf improvements. It is too early to know when that is going to be the case though. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10294289" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10294287</link><pubDate>Mon, 16 Apr 2012 22:36:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10294287</guid><dc:creator>Diego B Vega</dc:creator><description>&lt;p&gt;@cynic: Several internal classes and methods work together in the execution of EF queries. I hope this high level description will help you find the right methods when profiling your application, but keep in mind that details might change in future versions: &lt;/p&gt;
&lt;p&gt;- Execution of every regular LINQ query starts when we call ELinqQueryState.GetExecutionPlan. This method will perform the first part of the query translation - go from LINQ Expression tress to DbExpression trees, using ExporessionCoverter and other nested classes - every time. &lt;/p&gt;
&lt;p&gt;- Once we have a DbExpression tree we compute a key string based on it that we use to do a lookup in the query cache, using QueryCacheManager.TryCacheLookup. &lt;/p&gt;
&lt;p&gt;- If we find a match we will use the existing plan, which includes the final SQL generation. If we don&amp;#39;t find a match, we compute the plan with ObjectQueryExecutionPlan.Prepare and we add it to the cache (if the query is cacheable). &lt;/p&gt;
&lt;p&gt;- Interleaved with all this, we need to handle parameters: Most of the interesting logic for LINQ queries is in the Funcletizer class. &lt;/p&gt;
&lt;p&gt;- This class has a visitor that identifies access to closure variables that can be parameters in the LINQ expression tree an covertes them to an internal parameter class during the LINQ translation phase. &lt;/p&gt;
&lt;p&gt;- It also has the logic necessary to evaluate the parameter values from the variables captured in closures that we later pass to DbParameters in the target query. &lt;/p&gt;
&lt;p&gt;- Once we have the plan (an instance of ObjectQueryExecutionPlan), we pass the parameters to its Execute method, which will execute the command to obtain a DbDataReader which we will then pass to an instance of Shaper&amp;lt;T&amp;gt;, where the actual object materialization begins. &lt;/p&gt;
&lt;p&gt;From the first version of EF there has always been an improvement between the execution time of the first query for a given model and app domain and the execution time of the second one (even if it was a completely different query) because view generation for a given model and connection only needs to happen once per app domain. There has always also been an improvement between the first execution of a particular query instance and the second execution of *the same query instance* because we cache the query execution plan internally in the query instance. One of the things that EF 5.0 improves over what we had in EF 4.0 is that now if you create and execute the same query repeated times (think about the same query code constructing a new query instance on every round trip in a Web application) we can also take advantage of the cache. This case is different from the previous one in that different instance of the same query hit the same cache entry. &lt;/p&gt;
&lt;p&gt;The second part of the improvement in EF 5.0 is that when it comes to evaluating the values of parameters of LINQ queries in order to pass them to the underlying DbCommand, we do it in a way that is much more efficient. &lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;/p&gt;
&lt;p&gt;Diego&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10294287" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10293816</link><pubDate>Sat, 14 Apr 2012 21:01:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10293816</guid><dc:creator>Diego B Vega</dc:creator><description>&lt;p&gt;@Mark and Roger: Thanks guys for the great feedback. Definitely we see many applications that only require trivial mapping and a very short (if any) unit of work. Although we could create a new &amp;quot;lighter&amp;quot; version of EF optimized for those scenarios I believe we can improve the current EF so that you less often have to pay a performance tax for features you aren’t using. As David mentions, we know there is room for improvement in many areas. &lt;/p&gt;
&lt;p&gt;For specific feature requests, like optional unit of work and batch updates, I would like to encourage you to go to our UserVoice site (&lt;a rel="nofollow" target="_new" href="http://ef.mswish.net"&gt;http://ef.mswish.net&lt;/a&gt;), vote for them or add them if you cannot find them. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10293816" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10293768</link><pubDate>Sat, 14 Apr 2012 10:40:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10293768</guid><dc:creator>Roger - Fenêtre</dc:creator><description>&lt;p&gt;First of all thanks for investing serious time in such an important part of the framework. Performance is key in the success of every application. As we build a lot of disconnected web applications with EF, using short unit of works with the manager pattern and multiple users, first level caching and other objectcontext features are not very useful. Mark&amp;#39;s idea of a light context (with f.e. poco, fast (de)serialization and linq) in combination with second level caching would give super performance! As MS is going more and more to the disconnected world in W8, please consider this! The second level example yiou provided in the paper is not production ready. I would be great if this at least would be supported! Furthermore please consider to add bulk update and delete as this increases performance a lot and is a often used functionality is business apps (working example: &lt;a rel="nofollow" target="_new" href="https://github.com/loresoft/EntityFramework.Extended/blob/master/readme.md"&gt;github.com/.../readme.md&lt;/a&gt;). &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10293768" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10293659</link><pubDate>Fri, 13 Apr 2012 18:58:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10293659</guid><dc:creator>Mark</dc:creator><description>&lt;p&gt;Please consider making a EF-Lite, keep LINQ but have it work against plain objects, not run-time tweaks of any kind, no state tracking, nothing that woul get in the way of performance. LINQ would be only for compile-time checking and nothing else. The mantra should be performance above all! Keep it within x1-x1.5 of raw ADO.NET and you&amp;#39;ll see tons of big sites using it.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10293659" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10292565</link><pubDate>Wed, 11 Apr 2012 07:33:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292565</guid><dc:creator>cynic</dc:creator><description>&lt;p&gt;Also, could you tell what to methods look for on the call stack (in profilers and other tools) that correspond to the query execution stages outlined in &amp;quot;2. Cold vs. Warm Query Execution&amp;quot;, esp. how to distinguish between &amp;quot;Parameter Evaluation&amp;quot;, &amp;quot;Query Translation&amp;quot; and &amp;quot;Materializer Generation&amp;quot;? &lt;/p&gt;
&lt;p&gt;How exactly does the &amp;quot;but cached&amp;quot; &amp;nbsp;EF5 improvement work for &amp;quot;Query Translation&amp;quot; stage work? I am seeing and have always been seeing massive improvement during the second execution of a query in EF4 already (executed on different ObjectContext but with the same MetadataWorkspace), yet &amp;quot;Query Lookup&amp;quot; in EF4 is supposedly &amp;quot;Medium&amp;quot; cost, same as initial &amp;quot;Query Translation&amp;quot;.&lt;/p&gt;
&lt;p&gt;When can we expect official announcement on whether .NET 4.5 and EF5 core with it will support Windows XP? All the improvements would amount to nothing to those of us who have to support XP if &amp;nbsp;.NET 4.5 can&amp;#39;t be installed on in.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292565" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10292315</link><pubDate>Tue, 10 Apr 2012 17:40:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292315</guid><dc:creator>David Obando [MSFT]</dc:creator><description>&lt;p&gt;Hi Ricardo. Unfortunately, there&amp;#39;s no magic bullet for every model. We are working on performance improvements that will benefit everyone in upcoming releases of EF. Your feedback is taken serously and helps us define our priorities.&lt;/p&gt;
&lt;p&gt;The switch from independent associations to foreign keys will benefit larger projects over smaller ones. Complex models with many associations, a large number of entities (and properties) and with extensive use of inheritance will benefit the most from this switch. How large is the model of your sample code?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292315" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10292225</link><pubDate>Tue, 10 Apr 2012 13:21:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292225</guid><dc:creator>Ricardo GER</dc:creator><description>&lt;p&gt;I can not understand the point &amp;quot;2.4.1 Using Foreign Key Associations to reduce view generation cost&amp;quot;. Regardless of the sample code I run in a test, a model with &amp;quot;Foreign Key Associations&amp;quot; is always slower. I would appreciate an example or e-mail from you.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292225" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10292086</link><pubDate>Tue, 10 Apr 2012 01:55:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292086</guid><dc:creator>Sean Stenlund</dc:creator><description>&lt;p&gt;Thank you for this whitepaper. &amp;nbsp;Very informative and helpful at the right time. &amp;nbsp;It seems you EF folks are reading my mind at each stage of development on my project!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292086" width="1" height="1"&gt;</description></item><item><title>re: EF5 Performance Considerations</title><link>http://blogs.msdn.com/b/adonet/archive/2012/04/05/ef5-performance-considerations.aspx#10291641</link><pubDate>Sat, 07 Apr 2012 12:16:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10291641</guid><dc:creator>cynic</dc:creator><description>&lt;p&gt;@David Obando&lt;/p&gt;
&lt;p&gt;Nothing you&amp;#39;re not already aware of. You speak of the Navision model for which view generation takes over a month. Clearly, there is room for improvement there (and switching to FK associations is not an option, I want the features of independent associations and 104 minutes would still be way too much). I have a model for which view generation takes &amp;quot;only&amp;quot; 16 minutes, 15:30 of which consists of generating an update view for a single table (TPH, about 20 subtypes, participates in over a dozen associations), and it seems to double every month or so, as the team works on that entity set, and they hate it already (the problem appeared when we switched to TPH, if that&amp;#39;s any hint). &lt;/p&gt;
&lt;p&gt;You could also change the way views are distibuted, because with literal strings they take twice as much space as they could be (UTF-16) and you soon hit the literal string limit in CLR assemblies.&lt;/p&gt;
&lt;p&gt;Why not pregenerate the OfType query views as well? They&amp;#39;re not as expensive to create in the grand scheme of things, but ~2 secs extra cold startup time is unacceptable in desktop applications.&lt;/p&gt;
&lt;p&gt;Why not make the view generation efficient enough so that pre-generation is not necessary at all? &amp;quot;View generation&amp;quot; is your internal implementation detail, I haven&amp;#39;t heard of any other ORM forcing their implementation concerns on users to achieve their basic features.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10291641" width="1" height="1"&gt;</description></item></channel></rss>