perf: gate AvaloniaNLogSink at Warning, cache loggers#195
Open
perf: gate AvaloniaNLogSink at Warning, cache loggers#195
Conversation
Avalonia framework code emits high-volume Verbose/Debug/Info events during layout, input, and rendering. nlog.config blackholes Avalonia* events at those levels with a final="true" rule, so they have nowhere to go — but IsEnabled returning true unconditionally made Avalonia format arguments and call Log() before NLog discarded them. dotnet-trace on a script-editor typing session showed the sink consuming ~318ms of inclusive CPU over 30s, more than any other app-attributed path. Two changes: 1. IsEnabled now returns false below Warning. Avalonia short-circuits before formatting arguments, matching the intent of the existing nlog.config Avalonia* blackhole rule. 2. Per-source ILogger lookups go through a ConcurrentDictionary keyed by Type instead of LogManager.GetLogger(string) on each call. Smaller win after #1 since most calls don't reach Log anymore, but cheap enough to land together. Surviving Warning/Error/Fatal events flow through unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Avalonia framework code emits high-volume Verbose/Debug/Info events during layout, input, and rendering.
nlog.configalready blackholesAvalonia*events at those levels via afinal="true"rule, so they have nowhere to go — butAvaloniaNLogSink.IsEnabledreturningtrueunconditionally meant Avalonia still formatted arguments and calledLog()before NLog discarded the event.A
dotnet-tracecapture during a script-editor typing session showed this sink consuming ~318ms of inclusive CPU over a 30-second window — more than any other app-attributed path, and a noticeable fraction of UI-thread budget per keystroke.Changes
IsEnablednow returnsfalsebelowWarning. Avalonia short-circuits before formatting arguments, matching the intent of the existingAvalonia*blackhole rule innlog.config.ILoggerlookups go through aConcurrentDictionary<Type, ILogger>instead ofLogManager.GetLogger(string)on each call. Smaller win once number1 is in place but cheap enough to land together.Warning/Error/Fatal events flow through unchanged and still reach the console + logfile targets.