I am currently reading through the MSDN article, “Walkthrough: Creating an IQueryable LInQ Provider” and there is a lot of use of the ExpressionVisitor. ExpressionVisitor traverses the expression tree using the Visitor pattern.
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?
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. 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.