Real-world examples on optimizing .NET performance
summary
Realtime work on the RabbitMQ .NET client replaces MemoryStream+locks with sized frame objects, ArrayPool rentals, reduced allocations to 99 MB (from 7.14 GB) and drops allocated objects from ~4M to 1.8M, later down to ~30–40 MB. Techniques include stackalloc with fallback to ArrayPool, generics to avoid boxing, BinaryPrimitives for endian swaps (one instruction, ~95% faster), and channels as a single-writer buffer (used channels to eliminate per-frame locking). Benchmarks use BenchmarkDotNet and profilers like Visual Studio and JetBrains.
AI-written summary · about
chapters (23)
- 0:00Intro
- 0:55Memory Allocations
- 1:21Garbage Collection
- 1:55Garbage Collector Phases
- 2:18Gen 2
- 3:59Reference vs. value types
- 5:10Performance Tips
- 5:42Example: Convert a string to UTF8 bytes
- 9:39Allocation Benchmark
- 15:42Boxing - Benchmark
- 16:16Binary Serialization and Endianness
- 17:37Old: RabbitMQ .NET Client reading int64
- 18:44ASM Diff
- 19:17Binary Serialization Benchmark
- 19:33System.Threading.Channels
- 24:36Applying these optimizations in the real world
- 25:31AMQP Frame
- 27:13Problem 1
- 29:22Solving the problems
- 30:53Validating the changes
- 34:30JetBrains dotTrace
- 38:24PowerUp
- 39:04Questions?
related talks
01h 04mTurbocharged: Writing High-Performance C# and .NET Code
01h 14mTurbocharged: Writing High-performance C# and .NET code
47mUnlocking Performance Improvements in .NET
01h 00mPerformance Improvements in .NET 6
01h 01mTurbocharged: Writing High-Performance C# and .NET Code
57mPushing C# to the limit
56mState of the .NET Performance
01h 02mWriting high performance code in .NET
