serilog / serilog-extensions-logging

Serilog provider for Microsoft.Extensions.Logging
Apache License 2.0
313 stars 100 forks source link

Cache low-numbered numeric event ids to reduce allocations #142

Closed nblumhardt closed 5 years ago

nblumhardt commented 5 years ago

This is a quick improvement for #118. Needs a benchmark to measure allocs.

nblumhardt commented 5 years ago

Just a note, most of the framework projects now user, or will use, event ids: https://github.com/aspnet/AspNetCore/issues/6381

nblumhardt commented 5 years ago

Added some very basic, broad benchmarks. Shows (I think) that it's worth making this change, but also that there's a lot of opportunity still there in the allocations department.

BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=2.2.105
  [Host]     : .NET Core 2.2.6 (CoreCLR 4.6.27817.03, CoreFX 4.6.27818.02), 64bit RyuJIT
  DefaultJob : .NET Core 2.2.6 (CoreCLR 4.6.27817.03, CoreFX 4.6.27818.02), 64bit RyuJIT
Method Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Native 381.0 ns 41.01 ns 48.82 ns 1.00 0.00 0.0887 - - 280 B
NoId 1,004.2 ns 10.84 ns 10.14 ns 2.63 0.34 0.2785 - - 880 B
LowNumbered 1,367.0 ns 37.37 ns 104.80 ns 3.49 0.48 0.3529 - - 1112 B
HighNumbered 1,378.5 ns 27.65 ns 77.08 ns 3.67 0.43 0.3777 - - 1192 B