I understand that executing operations in different orders will yield different performance such as the difference between the following slow query:
List<TestItem> slowResults = items.OrderBy(item => item.StringItem)
.Where(item => item.IntItem == 100)
.ToList();
and this faster one:
List<TestItem> fastResults = items.Where(item => item.IntItem == 100)
.OrderBy(item => item.StringItem)
.ToList();
But that is not my question:
My question is about performance of the short circuiting as it relates to a LINQ predicate. When I use a Where clause, like in this case:
List<TestItem> results = items.Where(item => item.Item1 == 12 &&
item.Item2 != null &&
item.Item2.SubItem == 65 &&
item.Item3.Equals(anotherThingy))
.ToList();
Doesn't the order of the arguments matter? For instance, I would expect that doing a .Equals first would result in a slower query overall due to the Item1 == 12 integer evaluation being a much faster operation?
If order does matter, how much does it matter? Of course, calling methods like .Equals probably results is a much larger slow-down than if I was just comparing a few integers, but is it a relatively small performance penalty compared to how 'slow' LINQ operates? As LINQ makes tons of method calls, is something like .Equals really going to matter since--unless its overridden--it'll be executing native framework code, right? On the other hand, is a standard MSIL method call going to be significantly slower?
Also, are there any other compiler optimizations on this query which might be speeding this up under the hood?
Thanks for the thoughts and clarification! Brett