Measure Twice, Optimize Once: Real-World .NET Profiling with Visual Studio
summary
Demonstrates optimizing CSVHelper by running allocation and CPU traces with Visual Studio Profiler, attaching to BenchmarkDotNet benchmarks, and using the Copilot profiler agent to propose edits. Finds 640,000 zero-length array allocations (~15 MB and nearly 1s of GC pauses), adds a static empty-array to save allocations, and removes a junk array to improve wall-clock by ~14%. Replaces per-field expression compilation with a single compiled block to cut CPU from ~4.2ms to ~3.4ms and validates changes with benchmarks and unit tests.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 1:03Profiler usage poll
- 2:06Why profile and pipeline
- 5:58Demo setup and CSV Helper
- 7:00GitHub Copilot Profiler Agent memory
- 10:54Top insights and zero-length arrays
- 13:01Agent’s automated fixes
- 16:12Memory optimizations impact
- 18:23Boxed value type costs
- 21:34Memory to CPU demo transition
- 21:59Benchmark creation with Copilot
- 25:35Customizing benchmarks
- 26:17CPU usage profiling
- 28:24Hot paths analysis
- 29:46Delegate invocation overhead
- 33:35Validating improvements
- 36:03Edge cases and tests
- 37:50Key takeaways
- 39:16Q&A
related talks
01h 06mGet Better App Performance with this One Weird Trick
01h 03mTurbocharged: Writing High-Performance C# and .NET Code
01h 03mApplication Performance Optimisation in Practice
46mHigh Performance .NET
01h 02mApplication Performance Optimisation in Practice
04mInterview
58mLook Mommy, No GC!
01h 00mWriting Allocation Free Code in C#
