How can we help you today? How can we help you today?
springy
Another sample of hidden object creation, a LINQ query using "let" (against a LINQ-to-SQL AdventureWorks DB): from h in this.TransactionHistory.AsEnumerable() let x = h.ActualCost / h.Quantity where x > 0 let y = char.GetUnicodeCategory(h.TransactionType) orderby h.TransactionDate, y select h This gets translated to ILASM code whose C# translation looks like this: .Select ( h => new { h = h, x = (h.ActualCost . (Decimal)(h.Quantity)) } ) .Where (temp0 => (temp0.x > 0)) .Select ( temp0 => new { temp0 = temp0, y = Char.GetUnicodeCategory (temp0.h.TransactionType) } ) .OrderBy (temp1 => temp1.temp0.h.TransactionDate) .ThenBy (temp1 => temp1.y) .Select (temp1 => temp1.temp0.h) So although I'm using only a well known object (of type TransactionHistory) there have been created 2 additional anonymous (and temporary) classes for each instance of TransactionHistory I`m retrieving from the DB. While the temporary object most likely won't get promoted to Gen1 this still puts a load on GC collections which would be avoidable at all by refactoring the code into something smarter. / comments
Another sample of hidden object creation, a LINQ query using "let" (against a LINQ-to-SQL AdventureWorks DB):from h in this.TransactionHistory.AsEnumerable() let x = h.ActualCost / h.Quanti...
0 votes