Skip to content
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

Splat.NLog - Reduce allocation when creating new NLogLogger #1258

Merged
merged 2 commits into from
Dec 31, 2024

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Dec 31, 2024

What kind of change does this PR introduce?

What is the current behavior?

  • For every new NLogLogger then it will allocate new Array

What is the new behavior?

  • Store array from Enum.GetValues and reuse for every new NLogLogger
  • Improved AOT-support by using generic Enum.GetValues<T>

What might this PR break?

  • No breaking changes

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.71%. Comparing base (1803c70) to head (0bb0132).
Report is 184 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1258      +/-   ##
==========================================
- Coverage   71.87%   71.71%   -0.16%     
==========================================
  Files          96       96              
  Lines        4483     4430      -53     
  Branches      569      561       -8     
==========================================
- Hits         3222     3177      -45     
+ Misses       1074     1069       -5     
+ Partials      187      184       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -14,6 +14,7 @@ namespace Splat.NLog;
[DebuggerDisplay("Name={_inner.Name} Level={Level}")]
public sealed class NLogLogger : IFullLogger, IDisposable
{
private static readonly LogLevel[] _allLogLevels = Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>().ToArray();
Copy link
Contributor

@glennawatson glennawatson Dec 31, 2024

Choose a reason for hiding this comment

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

Use the Enum.GetValues<T> generic override, it's AOT compatible for future proofing.

Copy link
Contributor Author

@snakefoot snakefoot Dec 31, 2024

Choose a reason for hiding this comment

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

Enum.GetValues<T> is only available for NET5 (and newer). But good point about AOT-support. Added new commit.

Also verified that Enum.GetValues<T> allocates new array on every call, so caching still needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah caching is good. In AOT land they actually compile it to an array, but in non-AOT land its standard behavior.

@dpvreony dpvreony merged commit b14c4bc into reactiveui:main Dec 31, 2024
2 of 3 checks passed
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants