Lesson 8 of 40
Performance
Advanced
45 min
Performance Profiling & Diagnostics
Use the VS 2026 Diagnostics Hub, CPU profiler, memory profiler, and the new AI performance advisor to eliminate bottlenecks.
Part 1: The Diagnostics Hub
Open via Debug → Performance Profiler (Alt+F2). Available tools:
- CPU Usage — flame graphs and call trees
- Memory Usage — heap snapshots and leak detection
- Async Timing — visualize async/await overhead
- Database Queries — EF Core query analyzer
- Network — HTTP request timeline
Part 2: CPU Flame Graphs
Flame graphs show where CPU time is spent. Wider = more time. In VS 2026's profiler:
- Use Record CPU Profile during a realistic workload
- Filter by thread or time range
- Click any function to navigate to source
- Copilot can explain hotspots in plain English
Part 3: Memory Leak Detection
// Take two heap snapshots:
// 1. Baseline (after warm-up)
// 2. After suspected leak operation
// Compare snapshots — objects only in snapshot 2
// are candidates for leaks
// VS 2026: AI flags EventHandler leaks automatically
// "⚠ 23 instances of EventHandler not unsubscribed"
// 1. Baseline (after warm-up)
// 2. After suspected leak operation
// Compare snapshots — objects only in snapshot 2
// are candidates for leaks
// VS 2026: AI flags EventHandler leaks automatically
// "⚠ 23 instances of EventHandler not unsubscribed"
Part 4: BenchmarkDotNet Integration
VS 2026 integrates BenchmarkDotNet directly into the IDE:
[MemoryDiagnoser]
public class StringBenchmarks
{
[Benchmark]
public string Concat() => "a" + "b" + "c";
[Benchmark]
public string Interpolate() => $"{"a"}{"b"}{"c"}";
}
Run benchmarks via right-click → Run Benchmarks.public class StringBenchmarks
{
[Benchmark]
public string Concat() => "a" + "b" + "c";
[Benchmark]
public string Interpolate() => $"{"a"}{"b"}{"c"}";
}