A reporting endpoint I wrote months ago started turning up in our gen0 collection graphs, and for a while I couldn't work out why. All it does is total an amount column per region and hand back six numbers. Six. Nothing that small should be making the garbage collector sweat, but the allocation counter said otherwise, and that counter has never once flattered me.
The offending line was the one I'd have waved through in review without a second look:
var totals = rows . GroupBy ( r => r . Region ) . ToDictionary ( g => g . Key , g => g . Sum ( r => ( long ) r . Amount ));
Enter fullscreen mode
Exit fullscreen mode
It reads clean and does exactly what it says. And to produce those six sums, it first builds a grouping that holds every single row, bucketed by key, so it can walk each bucket and add things up. I only ever look at the totals.…