This integrates the well-tested template cache from serilog/serilog. In general, this will reduce allocations and speed up logging when events use templates properly (16 GB T470p):
Before
Method
Mean
Error
StdDev
Ratio
RatioSD
Gen 0
Gen 1
Gen 2
Allocated
Native
370.5 ns
7.067 ns
6.265 ns
1.00
0.00
0.0887
-
-
280 B
NoId
1,017.8 ns
10.906 ns
9.107 ns
2.75
0.04
0.2785
-
-
880 B
LowNumbered
1,318.5 ns
11.772 ns
10.435 ns
3.56
0.06
0.3529
-
-
1112 B
HighNumbered
1,363.2 ns
20.672 ns
18.325 ns
3.68
0.07
0.3777
-
-
1192 B
After
Method
Mean
Error
StdDev
Ratio
RatioSD
Gen 0
Gen 1
Gen 2
Allocated
Native
362.2 ns
3.419 ns
3.031 ns
1.00
0.00
0.0887
-
-
280 B
NoId
604.3 ns
11.431 ns
10.133 ns
1.67
0.03
0.1421
-
-
448 B
LowNumbered
843.9 ns
12.429 ns
11.018 ns
2.33
0.04
0.2155
-
-
680 B
HighNumbered
878.3 ns
17.330 ns
16.211 ns
2.43
0.03
0.2413
-
-
760 B
Performance might regress in apps that (mis)use string concatenation to construct log messages, but the benefits for carefully-written have been found to outweigh this downside in our experiences with Serilog to date.
This integrates the well-tested template cache from
serilog/serilog
. In general, this will reduce allocations and speed up logging when events use templates properly (16 GB T470p):Before
After
Performance might regress in apps that (mis)use string concatenation to construct log messages, but the benefits for carefully-written have been found to outweigh this downside in our experiences with Serilog to date.