-
Notifications
You must be signed in to change notification settings - Fork 5.2k
FormattedLogValues - Small optimization for index operator #122059
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
base: main
Are you sure you want to change the base?
Conversation
5bec10c to
437108d
Compare
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.
Pull request overview
This PR optimizes the indexer operator in FormattedLogValues by removing a redundant check for the last element (original format). Previously, the indexer explicitly checked if index == Count - 1 to return the original format, but this check was redundant since LogValuesFormatter.GetValue() already handles this case. The optimization reduces execution time by ~20% (from 5.4ns to 4.3ns) by delegating all logic to GetValue when a formatter exists, eliminating the duplicate check.
Key changes:
- Restructured indexer logic to check for null formatter/values upfront and delegate to
GetValueotherwise - Removed redundant
index == Count - 1check sinceGetValuehandles the last index internally
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs
Outdated
Show resolved
Hide resolved
dc672d0 to
b83ddbe
Compare
|
Tagging subscribers to this area: @dotnet/area-extensions-logging |
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/FormattedLogValues.cs
Show resolved
Hide resolved
tarekgh
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.
LGTM, thanks @snakefoot!
Resolves #122046 (Removed "expensive" Count-check, since also exists in
LogValuesFormatter)Benchmark code: