Repository navigation
Don't log false-condition expansion unnecessarily - #12226
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes unnecessary expansion and logging of false condition expressions during low-verbosity builds or design-time builds, improving performance and reducing exception counts. The change adds a verbosity check to prevent string expansion when the logging output would be discarded anyway.
- Adds a verbosity check to prevent condition expansion when verbosity is low
- Extends the existing
OnlyLogCriticalEventscheck with aMinimumRequiredMessageImportancecondition - Reduces unnecessary string processing and potential exceptions during builds
8d02f09 to
c76b62e
Compare
This came up in investigating devdiv2535034, which was a regression in exception count caused by a property function within a condition throwing an exception when fully stringified (but not on normal expansion due to short-circuiting condition evaluation). But the problem is more broad--during a design-time build or even a regular build at low verbosity, these low-pri events would just be thrown away. Extend the OnlyLogCriticalEvents check to include verbosity for the logging-only expansion of a false condition.
c76b62e to
a18d2ab
Compare
| _state = TargetEntryState.Completed; | ||
|
|
||
| if (!projectLoggingContext.LoggingService.OnlyLogCriticalEvents) | ||
| if (projectLoggingContext.LoggingService.MinimumRequiredMessageImportance > MessageImportance.Low && |
There was a problem hiding this comment.
When Verbosity is diagnostic, this becomes true:
msbuild/src/Build/Logging/ConsoleLogger.cs
Lines 486 to 489 in 98fe185
then the added condition in this PR is false?
Generally speaking, I think the condition added in this PR is simply always false. The maximum value of MessageImportance enum is Low (and there are no casts from int to the enum anywhere in the codebase it seems). I think the condition should be >=, not >.
There was a problem hiding this comment.
I cannot believe that enum is ordered backward. Will fix.
dotnet#12226 introduced a bug: MessageImportance.Low is (numerically) the highest value, so nothing is ever greater than it is. Reverse the comparison and extract a method to avoid this confusion in the future.
Respect OnlyLogCriticalEvents when tasks query whether messages of a given importance are enabled. Replace unreachable MinimumRequiredMessageImportance > Low checks for false task and target conditions with IsMessageEnabled. This preserves the optimization from dotnet#12226 at normal verbosity while restoring expanded skip details at detailed and diagnostic verbosity. Add coverage for task-facing importance queries and false-condition details across normal, detailed, and diagnostic loggers.
Replace unreachable MinimumRequiredMessageImportance > Low checks for false task and target conditions with IsMessageEnabled. This preserves the optimization from dotnet#12226 at normal and lower verbosity while restoring expanded skip details at detailed and diagnostic verbosity. Add coverage using real console loggers across normal, detailed, and diagnostic verbosity.
Replace unreachable MinimumRequiredMessageImportance > Low checks for false task and target conditions with IsMessageEnabled. This preserves the optimization from dotnet#12226 at normal and lower verbosity while restoring expanded skip details at detailed and diagnostic verbosity. Add coverage using real console loggers across normal, detailed, and diagnostic verbosity.
Replace unreachable MinimumRequiredMessageImportance > Low checks for false task and target conditions with IsMessageEnabled. This preserves the optimization from dotnet#12226 at normal and lower verbosity while restoring expanded skip details at detailed and diagnostic verbosity. Add coverage using real console loggers across normal, detailed, and diagnostic verbosity.
This came up in investigating devdiv2535034, which was a regression in exception count caused by a property function within a condition throwing an exception when fully stringified (but not on normal expansion due to short-circuiting condition evaluation).
But the problem is more broad--during a design-time build or even a regular build at low verbosity, these low-pri events would just be thrown away.
Extend the
OnlyLogCriticalEventscheck to include verbosity for the logging-only expansion of a false condition.With this change I don't see any
FormatExceptions orTruncateStringcalls loading OrchardCore or Roslyn solutions.