简体   繁体   English

使用ExpressionVisitor是否有性能方面的考虑?

[英]Are there any performance considerations to using ExpressionVisitor?

I am currently reading through the MSDN article, "Walkthrough: Creating an IQueryable LInQ Provider" and there is a lot of use of the ExpressionVisitor. 我目前正在阅读MSDN文章“演练:创建IQueryable LInQ提供程序”,并且ExpressionVisitor的用法很多。 ExpressionVisitor traverses the expression tree using the Visitor pattern. ExpressionVisitor使用“访问者”模式遍历表达式树。

http://msdn.microsoft.com/en-us/library/bb546158.aspx http://msdn.microsoft.com/en-us/library/bb546158.aspx

It would seem to me that traversing an Expression tree over and over like this would be costly to performance. 在我看来,像这样一遍遍遍遍表达式树会提高性能。 Is that true? 真的吗? Should I be concerned about this when creating my IQueryProvider? 创建IQueryProvider时,我应该担心这一点吗?

Basically, yes. 基本上是。 Expression trees can become quite big so traversing them and potentially creating copies due to changes can take a while. 表达式树可能会变得很大,因此遍历它们并可能由于更改而潜在地创建副本可能需要一段时间。 LINQ to SQL and EF often use more CPU on the client than in SQL Server because they excessively manipulate the Expression AST. 与SQL Server相比,LINQ to SQL和EF通常在客户端上使用更多的CPU,因为它们过多地操纵了AST表达式。 It is really severe and shows up in profiler traces big time. 这确实很严重,并且在分析器跟踪中显示的时间很长。

If it does matter depends on how often you're doing it and what else your provider does. 是否重要取决于您执行操作的频率以及提供商的其他功能。 Not sure what else to say about it. 不知道还有什么要说的。 No operation is slow or fast by itself. 任何操作本身都不是缓慢的还是快速的。 It depends on what you need and how often you execute it. 这取决于您需要什么以及执行它的频率。

That said, expression visitors are an elegant pattern and have their place. 就是说,表情访客是一种优雅的模式,并且有自己的位置。

Not Really. 并不是的。 Parsing an abstract syntax tree with a visitor pattern is pretty standard. 用访问者模式解析抽象语法树是相当标准的。 Usually when making an IQueryable provider the amount of time you spend parsing a handful nodes in an expression tree is going to be completely dwarfed by the amount of time you spend fetching data. 通常,在创建IQueryable提供程序时,花在解析表达式树中少数几个节点上的时间将与花在获取数据上的时间完全相形见war。

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

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