Performance .Where(filter).First() when using .Where(filter).First() rather than .First(filter) will usually be very small.
However, they do not match - Where generates a new iterator, which First can simply take one element, while First(filter) can micro-optimize using only one loop and direct return whenever filter matches.
So, although both approaches have the same semantics and both perform filter same way (only as often as necessary), using First with the filter parameter does not require creating an intermediate iterator object and, possibly, avoids some very simple method calls on this iterator.
In other words, if you execute such code millions of times, you will see a small difference in performance - but nothing huge; I would never worry about that. Whenever this tiny performance difference actually matters, itβs much easier for you to write a (very simple) foreach-with-if statement that is equivalent and avoids the extra calls and object distributions inherent in LINQ β but remember, this is microoptimization, which you will rarely need to.
Edit: Test showing effect:
It takes 0.78 seconds:
for(int i=0;i<10*1000*1000;i++) Enumerable.Range(0,1000).First(n=> n > 2); GC.Collect();
But it takes 1.41 seconds:
for(int i=0;i<10*1000*1000;i++) Enumerable.Range(0,1000).Where(n=> n > 2).First(); GC.Collect();
While simple loops are much faster (0.13 seconds):
long bla = 0; for(int i=0;i<10*1000*1000;i++) for(int n=0;n<1000;n++) if(n > 2) { bla+=n; break; } GC.Collect(); Console.WriteLine(bla);
Please note that this test only shows such extreme differences, because I have a trivial filter and a very short mismatching prefix.
Based on some quick experiments, the difference seems to be largely explained by the details by which the encoding takes place. Thus, for an array and List<> first option is actually faster, most likely it will make a special wrapper in .Where for those types that First does not have; for custom iterators, the second version is slightly faster, as expected.
Summary:
.Where(...).First() about as fast as .First(...) - you should not choose one or another optimization. In the general case, .First(...) very slightly faster, but in some common cases it is slower. If you really need this microoptimization, use simple loops that are faster than either.