Conversation
benaadams
commented
Sep 26, 2015
- Only create logger array when loggers
- Normal for loop condition in constructor
- Log nop when no loggers
- BeginScope to return null when no loggers
- Logging is disabled when no loggers
- Add provider to only create one resized array; rather than several
Hi @benaadams, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! The agreement was validated by .NET Foundation and real humans are currently evaluating your PR. TTYL, DNFBOT; |
Hmm, takes the allocations from 12,000 objects -> 4,020 objects but memory is same; needs work |
/cc @lodejard |
a3c15bc
to
2676a4e
Compare
Rebased |
This doesn't resolve issues with the actual log calls boxing and struct wrapping; whether or not its going to log anything; but I believe this is being addressed elsewhere |
@@ -96,10 +108,16 @@ public bool IsEnabled(LogLevel logLevel) | |||
|
|||
public IDisposable BeginScopeImpl(object state) | |||
{ | |||
if (_loggers == null) | |||
{ | |||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When _loggers == null
return a singleton IDisposable object which does nothing in the Dispose method. No allocations, but BeginScopeImpl can always returned a non-null value.
Also when _loggers.Count == 1
you can return _loggers[0].BeginScopeImpl(state)
- there's no reason to create an aggregate disposable around a single instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done