FSharp.Logf icon indicating copy to clipboard operation
FSharp.Logf copied to clipboard

`logf` adds overhead for noop `ILogger`

Open jwosty opened this issue 2 years ago • 0 comments

logf has some overhead from all the string manipulation and reflection that is happening behind the scenes. It's completely negligible for loggers which perform real I/O (like a Serilog logger pointed at a file), but a potential bottleneck for ones that don't (like NullLogger). In the latter situation, logf introduces a 100x slowdown.

I'm still using this library in my own applications because the real overhead is the filesystem I/O, not logf. This really shouldn't stop you from using the library, unless you have performance requirements which also prevent you from using vanilla printf.

The only way I can think to optimize this is to somehow delay the string scanning and printf analysis until the logger requests formatting, instead of performing it before calling ILogger.Log. I'm unsure whether or not this is even possible.

Benchmarks: https://github.com/jwosty/FSharp.Logf/blob/benchmark/master/BenchmarkDotNet.Artifacts/results/Benchmark.Benchmarks-report-github.md

jwosty avatar Jun 05 '23 15:06 jwosty