Skip to content

Don't log false-condition expansion unnecessarily - #12226

Merged
rainersigwald merged 1 commit into
mainfrom
exp/raines/log-conditions-less
Jul 29, 2025
Merged

rainersigwald merged 1 commit into
mainfrom
exp/raines/log-conditions-less

Conversation

@rainersigwald

Copy link
Copy Markdown
Member

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.

With this change I don't see any FormatExceptions or TruncateString calls loading OrchardCore or Roslyn solutions.

Copilot AI review requested due to automatic review settings July 25, 2025 22:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 OnlyLogCriticalEvents check with a MinimumRequiredMessageImportance condition
  • Reduces unnecessary string processing and potential exceptions during builds

@rainersigwald
rainersigwald force-pushed the exp/raines/log-conditions-less branch from 8d02f09 to c76b62e Compare July 25, 2025 22:38
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.
@rainersigwald
rainersigwald force-pushed the exp/raines/log-conditions-less branch from c76b62e to a18d2ab Compare July 25, 2025 22:48
@rainersigwald
rainersigwald merged commit d383f82 into main Jul 29, 2025
@rainersigwald
rainersigwald deleted the exp/raines/log-conditions-less branch July 29, 2025 20:16
_state = TargetEntryState.Completed;

if (!projectLoggingContext.LoggingService.OnlyLogCriticalEvents)
if (projectLoggingContext.LoggingService.MinimumRequiredMessageImportance > MessageImportance.Low &&

@Youssef1313 Youssef1313 Aug 26, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When Verbosity is diagnostic, this becomes true:

if (Verbosity >= BaseConsoleLogger.ImportanceToMinimumVerbosity(MessageImportance.Low, out _))
{
return MessageImportance.Low;
}

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 >.

@rainersigwald @YuliiaKovalova

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I cannot believe that enum is ordered backward. Will fix.

rainersigwald added a commit to rainersigwald/msbuild that referenced this pull request Aug 26, 2025
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.
DustinCampbell added a commit to DustinCampbell/msbuild that referenced this pull request Oct 15, 2026
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.
DustinCampbell added a commit to DustinCampbell/msbuild that referenced this pull request Oct 15, 2026
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.
DustinCampbell added a commit to DustinCampbell/msbuild that referenced this pull request Oct 15, 2026
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.
DustinCampbell added a commit to DustinCampbell/msbuild that referenced this pull request Oct 16, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants