Performance problems in production are often invisible until they are catastrophic. Proactive performance engineering, supported by profiling tools and production measurement, finds and fixes issues before they become incidents.

Memory allocation profiling

Excessive memory allocation is the most common .NET performance issue. Allocating large objects on the large object heap (objects >85KB) triggers generation-2 garbage collection which pauses all managed threads. Profilers (dotTrace, Visual Studio Diagnostic Tools, PerfView) identify allocation hot paths: the methods that allocate most frequently and the object types that dominate the heap. Reducing allocation in hot paths, using ArrayPool, Span, and StringBuilder instead of creating new collections, has measurable impact on GC pause times.

CPU profiling with sampling

Sampling profilers periodically capture a stack trace of all running threads and aggregate them into a flame graph showing where the application spends its CPU time. The hot path visible in a flame graph, the wide blocks near the base, shows where optimisation effort should focus. CPU profiling under realistic load (load testing, production sampling) is more informative than profiling under synthetic benchmarks.

Async performance anti-patterns

.NET async/await introduces specific performance traps: async void methods that swallow exceptions, .Result or .Wait() calls that block threads (defeating the purpose of async), excessive ConfigureAwait(false) omissions that marshal continuations back to the synchronisation context unnecessarily, and async operations in tight loops that generate excessive Task allocations. Each of these patterns is visible in a memory or CPU profile.

BenchmarkDotNet for micro-benchmarks

BenchmarkDotNet provides a rigorous micro-benchmarking framework for .NET. It handles JIT warm-up, GC interference, and statistical significance, the common pitfalls of hand-rolled benchmarks. BenchmarkDotNet is the standard for measuring the performance of library code and evaluating the impact of optimisations. The output includes mean, standard deviation, allocations, and comparison between baseline and candidate implementations.