Writing (in)efficient C#
summary
Shows concrete inefficiencies and fixes: repeated enumeration and lazy IEnumerables cause multiple full iterations (demo reduces ~10–12 enumerations to one); List/array resizing doubles capacity (256 → 512) and wastes memory; add range avoids repeated resizes; async/Parallel and correct DI lifetimes cut work. Benchmarks use BenchmarkDotNet (string builder wins, “is” null checks beat Equals). Production tools include dotnet-counters, dotnet-dump, DotTrace/ANTS and Application Insights. Billion-row example drops from ~6 minutes to 2m then ~5s with low-level optimisations.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 4:22How .NET works
- 9:37Collection misuse
- 12:46Enumerators in .NET
- 17:21Array and list inefficiencies
- 23:24Live demo: inefficient patterns
- 35:25Parallel and async in .NET
- 39:38DI lifetimes and disposal
- 42:28Proper use of memory caches
- 45:25Benchmarking C# code
- 50:29Profiling tools
- 53:16Billion row challenge
- 57:11Resources
related talks
47mUnlocking Performance Improvements in .NET
01h 01mTurbocharged: Writing High-Performance C# and .NET Code
56mState of the .NET Performance
01h 14mTurbocharged: Writing High-performance C# and .NET code
52mPerformance features in C#
59mPerformance tricks I learned from contributing to open source .NET packages
37mRock Your Code Code and App Performance for Microsoft .Net
43mPragmatic Performance: When to care about perf, and what to do about it.
