-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add generic log message to avoid lambda allocations. #78128
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
Add generic log message to avoid lambda allocations. #78128
Conversation
|
@ToddGrun @JoeRobich ptal. |
|
@JoeRobich @dibarbet @ToddGrun @tmat ptal. |
| if (_lazyMap == null) | ||
| { | ||
| _lazyMap = SharedPools.Default<Dictionary<string, object?>>().AllocateAndClear(); | ||
| _propertySetter.Invoke(_lazyMap, _args); |
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.
| public static GenericKeyValueLogMessage<TArgs> Create( | ||
| Action<Dictionary<string, object?>, TArgs> propertySetter, TArgs args, LogLevel logLevel) | ||
| { | ||
| var logMessage = s_pool.Allocate(); |
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.
| LogLevel = logLevel; | ||
| } | ||
|
|
||
| public static new SimpleKeyValueLogMessage Create(Action<Dictionary<string, object?>> propertySetter, LogLevel logLevel = LogLevel.Information) |
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.
| { | ||
| private static readonly ObjectPool<SimpleKeyValueLogMessage> s_pool = new(() => new()); | ||
|
|
||
| private Action<Dictionary<string, object?>>? _propertySetter; |
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.
|
Love it! I notice these allocations when I'm looking at the code, but it never seems to pop in a profile. Death by a thousand papercuts, I suppose. In reply to: 2798487395 |
|
@ToddGrun ok with signing off? I can handle the mop up in a new pr. |
ToddGrun
left a comment
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.
![]()
No description provided.