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
ColoredConsoleTarget performance improvements. #1112
Conversation
Current coverage is
|
/// Gets the compiled regular expression that matches either Text or Regex property. | ||
/// </summary> | ||
public Regex CompiledRegex | ||
private Regex CompiledRegex |
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.
This is an unneeded breaking change?
I reverted the breaking change in |
{ | ||
var matchingRule = GetMatchingRowHighlightingRule(logEvent); | ||
|
||
if ((matchingRule.ForegroundColor != ConsoleOutputColor.NoChange) && ((ConsoleColor)matchingRule.ForegroundColor != oldForegroundColor)) |
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.
Can we extract this to a method? (DRY)
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.
Done.
Hi, Thanks for this PR! Just reviewed the code. two notes. Also, I think I think it would be nice to remove the regex fully when it's just a string replace, although I can be hard to keep that backwards-compatible. What do you think? |
I tested this and it yields no significant difference in performance, so it's probably not worth adding the additional complexity to the code. |
Xamarin license issue again :( |
My local machine seems to incorrectly unload the licenses. :( |
fixed. The deadlocked machines took some Xamarin licenses as my PC (deactivated now) |
{ | ||
var matchingRule = GetMatchingRowHighlightingRule(logEvent); | ||
|
||
if (ColorDoesChange(matchingRule.ForegroundColor, oldForegroundColor)) |
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.
I think this is easier to read:
var didChangeForegroundColor = ColorDoesChange(matchingRule.ForegroundColor, oldForegroundColor)`
if(didChangeForegroundColor ){}
what do you think?
Thanks for the good proposals! I agree and I applied them. |
Great! Thanks! 👍 |
ColoredConsoleTarget performance improvements.
Fixes #980
I've identified the expensive operations to be the
ForegroundColor
andBackgroundColor
properties (both get and set), and theTextWriter.Write()
andTextWriter.WriteLine()
methods.I've applied two performance enhancements:
WriteLine(message)
the message instead of doing aWrite(message)
followed by aWriteLine()
. This saves one expensiveWrite()
call per log.To test the performance I built a program that logs 2000 messages and every 13th message is done with a different log level causing that message to appear in a different color. All other messages appear in the default console colors.
Before applying any of the improvements, the logging took 0.8 seconds on average. The
ConsoleTarget
takes about 0.25 seconds to log the same messages.Change (1) yields an improvement of about 38 %, and change (2) yields an improvement of about 46 %.
Together, the two changes decrease the running time from 0.8 seconds to about 0.33 seconds; a total improvement of about 59 %. It is also quite close to the
ConsoleTarget
time of 0.25 seconds.