-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update NLogLoggerFactory.cs #405
Conversation
Added double-checked locking to minimize locking performance impact.
@snakefoot looks fine to me, agree? |
Codecov Report
@@ Coverage Diff @@
## master #405 +/- ##
========================================
- Coverage 82.02% 82% -0.03%
========================================
Files 12 12
Lines 1174 1178 +4
Branches 193 194 +1
========================================
+ Hits 963 966 +3
Misses 141 141
- Partials 70 71 +1
Continue to review full report at Codecov.
|
Not sure I understand the requirement for this change. @akovac35 Are you actually using this class? and where do you have performance issues? Instead of racing around in an unsafe container without underwear, then I would probably do one of the following:
But I'm curious why something that works for Microsoft Extension Logging is not good enough for NLog.Extensions.Logging. So curious where you experience performance issues? (Especially since NLog LoggerFactory is not used by default) |
Well in this case there is simply no need to do any locking for the reading part. If an object already exists, there is no need to lock anything and simply return the object, if it doesn't - then do the locking and check again if the object was inserted just before the lock occurred. The Microsoft's implementation should be fixed as well, there is much needless locking on many places in the overall .NET Core implementation. So to promote a general practice, this pull request should be excepted. |
So you just want to make unsafe code because it feels better?
If you can convince Microsoft with a merged pull-request for their repository, then I don't mind changing NLogLoggerFactory so it is in sync again with theirs.
|
Ok, I will try with them first. I don't see what could be unsafe about the proposed change though. Is this a general concern over design ambiguity originating from MS implementation? |
Yes the dictionary with lock was introduced to align with Microsoft implementation.
Dictionary lookups are not safe when other thread is mutating the collection. Hence why ConcurrentDictionary was invented. But if changes are made to Microsoft LoggerFactory then please tell so we can align.
|
You are correct. I will cancel this pull request. |
Added double-checked locking to minimize locking performance impact.