Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Reduce allocs when no loggers #254

Merged
merged 2 commits into from Nov 4, 2015

Conversation

benaadams
Copy link
Contributor

  • 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

@dnfclas
Copy link

dnfclas commented Sep 26, 2015

Hi @benaadams, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@benaadams
Copy link
Contributor Author

Hmm, takes the allocations from 12,000 objects -> 4,020 objects but memory is same; needs work

@benaadams
Copy link
Contributor Author

K, is good...

Before Allocations 12000 per 4k
pre-allocs
Before Bytes 448kB per 4k
pre-bytes

After Allocations 8000 per 4k
post-allocs
After Bytes 256kB per 4k
post-bytes

@davidfowl
Copy link
Member

/cc @lodejard

@davidfowl davidfowl added this to the 1.0.0-rc1 milestone Oct 12, 2015
@davidfowl davidfowl added the Perf label Oct 12, 2015
@benaadams
Copy link
Contributor Author

Rebased

@benaadams benaadams changed the title Reduce logging allocs Reduce allocs when no loggers Oct 18, 2015
@benaadams
Copy link
Contributor Author

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;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lodejard
Copy link
Contributor

lodejard commented Nov 4, 2015

:shipit:

lodejard added a commit that referenced this pull request Nov 4, 2015
@lodejard lodejard merged commit 1dd0d27 into aspnet:dev Nov 4, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants