Writing Allocation Free Code in C#
summary
Explains concrete C# features and measurements that cut GC pauses: shows how ref returns/ref locals and ref readonly/in stop needless copies, how readonly and ref structs prevent defensive copies, and how Span<T>/Memory<T> enable slicing contiguous memory without allocations. Demonstrates unit tests that record zero allocations and cites System.Text.Json using spans to make JSON deserialization roughly two times faster in some benchmarks. Emphasizes these are micro‑optimizations for hot paths and requires profiling before applying.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 2:25Garbage Collection
- 6:11LowHanging Fruit
- 9:23Reference Types and Value Types
- 12:53Closures and Iterators
- 18:38Value Types
- 22:05Ref Returns
- 28:48Ref ReadOnly
- 33:38Method Argument Modifier
- 36:43ReadOnly struct
- 46:48Ref structs
- 51:28SystemTextJason
- 53:28Micro Benchmarks
- 57:51Summary
related talks
43mWriting Allocation Free Code in C#
51mWriting Allocation Free Code in C#
01h 03mTurbocharged: Writing High-Performance C# and .NET Code
42mMeasure Twice, Optimize Once: Real-World .NET Profiling with Visual Studio
58mLook Mommy, No GC!
39mMemory Efficient Java
44mStaying friendly with the GC
01h 01mTurbocharged: Writing High-Performance C# and .NET Code
