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
Struct alternative to LogEventProperty; optimizations #1315
Conversation
Nested logger creation (.NET Core 2.2)Removed an allocation (15% fewer bytes on the most common two cases); added a small Before:
After:
|
Binding benchmark (.NET Core 2.2)The PR introduces a regression in To quantify: Before:
After:
|
I think this is ready to go, but I can't figure out why the UWP tests are failing on the newer SDK (not running a version of VS that suppports UWP projects :-)) Anyone have any ideas? 😊 |
😓 ... going .. to ... get .. this ... building ... on new SDK! |
👏 building! Anyone keen to sanity check this? :-) |
(Will need a squash/merge.) The churn here is due to wanting to use newer C# features - |
If all's quiet I'll shoot this through to |
LGTM |
Thanks for the quick scan, @merbla and @adamchester ... Hitting that button now! :-) |
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.
LGTM
Includes a .NET SDK and AppVeyor build image update.
This replaces some internal usage of the class
LogEventProperty
with a new, very similar, structEventProperty
.The changes reduce allocations in message template binding/event construction, and in
ForContext(name, value)
, by a very modest amount.Along the way, a couple of small opportunistic changes - some
IEnumerable<T>
over arrays was replaced with direct array passing, and copying of events (i.e. forWriteTo.Logger()
) was refactored to allow the new event's properties dictionary to be constructed with the correct capacity.Pipeline benchmark (.NET Core 2.2)
This shows 56 fewer bytes allocated (12%) when binding/constructing a log event with one property. The gain here will be in proportion to the number of properties bound from the message template.
The difference is consistent across .NET Core and Framework.
Before:
After:
Remaining work
Some more benchmarking is needed. I ran the allocations benchmark suite but apart from in the simple logging case that matches the pipeline benchmark above, differences were mostly noise, buried by the other work being done.
There also remains a regression in
Logger.BindMessageTemplate()
due to the need to presentLogEventProperty
s on the API surface.