PageHits Middleware: Minimal-Allocation Request-Counting Pipeline in ASP.NET Core 10
Take the ASP.NET Core 10 middleware that writes a dbo.PageHits row per request and drive its allocation profile near zero: Span<char> for path/UA parsing, IMemoryCache 30-second dedup, fire-and-forget Task.Run INSERT. Under a synthetic 50K req/minute load, Gen0 GC drops from 15% to 2% and P99 latency goes 12ms → 3ms. Full code, dotnet-counters measurements, Span optimization traps and fire-and-forget gotchas all in one — straight from the live bilalkose.com.tr system.