-
Notifications
You must be signed in to change notification settings - Fork 829
Closed
Labels
Description
Is your feature request related to a problem? Please describe.
I am considering replacing our in house logging solution for Unity3D with Serilog but it allocates 3x more memory for logging a simple string.
Describe the solution you'd like
Using a few quick experiments I found that we could bring the allocations to the same minimal level with these 3 changes:
- Use foreach over _outputTemplate.TokenArray instead of Tokens IEnumerator in MessageTemplateTextFormatter.Format method so no IEnumerator is allocated.
- Pool and reuse internally created StringWriters using writer.GetStringBuilder.Clear().
- Pool and reuse LogEvent instances.
Additional context
If you agree this would be useful I could make a pull request. It would be nice if I could use ConcurrentBag for the pools but we would have to sack .netstandard1.0 since it is not supported there.