Skip to content

Conditionally skipped targets may lead to bad performance of a build. #11753

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

Open
AR-May opened this issue Apr 23, 2025 · 2 comments · May be fixed by #11766
Open

Conditionally skipped targets may lead to bad performance of a build. #11753

AR-May opened this issue Apr 23, 2025 · 2 comments · May be fixed by #11766

Comments

@AR-May
Copy link
Member

AR-May commented Apr 23, 2025

Description

When building a project:

  • If a target is skipped due to a condition during the project's build, and
  • Other projects depend on this target (commonly an initial target)

This situation can cause delays in the build process for dependent projects.

Symptoms

  • Significant variance in build times between builds.
  • MSBuild tasks show inconsistent performance between builds.
  • When switching to graph build mode, MSBuild tasks take considerably longer to resolve than expected (they should normally resolve almost immediately).

Technical details

When the initial target of a project (or another target necessary for a dependent project's build) is skipped due to a condition:
-The ResultsCache does not resolve this target in the main node when the build results are requested by a dependent project.
-Instead, the project is rescheduled to build the skipped target again. It waits in the queue for a build node, and if the condition still evaluates to false, the node resolves the target immediately with the same "skipped" result.
-If the build node is occupied, this can lead to delays in the overall build process.
For more details, refer to #11637.

Fix

To address this issue:

  1. Check for conditional targets on which dependent projects rely (e.g., conditional initial targets).
  2. If such targets are found, consider:
    • Removing the condition, or
    • Removing the dependency link from this target.
@AR-May AR-May self-assigned this Apr 23, 2025
@AR-May AR-May linked a pull request Apr 25, 2025 that will close this issue
@AR-May
Copy link
Member Author

AR-May commented Apr 28, 2025

We have had a fix idea: by default accept "skipped" as a valid result for the target and let skipped targets not to cause ResultsCache miss.

It seems like current behavior on conditional targets would not allow us to make this change. See this test. The condition outside of the target is evaluated during evaluations, conditions inside of the target - on runtime, but conditions on the target itself are computed also during the run. So, there could be situation when the skipped target gets executed again and the condition could be evaluated differently: documentation link. Whoever relies on this behavior might be broken if the target would be resolved from the results cache as skipped.

@AR-May AR-May changed the title Conditionally skipped initial target results in ResultsCache miss. Conditionally skipped targets may lead to bad performance of a build. Apr 30, 2025
@AR-May
Copy link
Member Author

AR-May commented May 12, 2025

Next steps: revisit SDK and MSBuild common targets and fix the issue there instead of modifying the MSBuild behavior, similar as arcade fix was done: dotnet/arcade#15743.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant