Skip to content
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

Process-wide caching of ToolsetConfigurationSection #6832

Merged
merged 2 commits into from Sep 14, 2021

Conversation

rokonec
Copy link
Contributor

@rokonec rokonec commented Sep 9, 2021

Fixes #6667

Context

Tools configuration is read from MSBuild.exe.config multiple time. We can simply cache related configuration section to optimize config file access.
Changes are under opt-out escape hatch.

Changes Made

Cached in static variable. Caching is not applied in unit tests cases.

Testing

Rebuilds and incremental build of orchard core.
ETL has been captured to verify reading from MSBuild.exe.config was optimized.

Notes

When measured the real perf difference in both CPU and wall-clock time was negligible/non-verifiable.

to eliminate multiple loading MSBuild.exe.config
@@ -250,6 +257,18 @@ protected override IEnumerable<ToolsetPropertyDefinition> GetSubToolsetPropertyD
/// Unit tests wish to avoid reading (nunit.exe) application configuration file.
/// </summary>
private static Configuration ReadApplicationConfiguration()
{
if (Environment.GetEnvironmentVariable("MSBUILDCACHETOOLSETCONFIGURATION") != "0")
Copy link
Member

Choose a reason for hiding this comment

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

Why a separate opt-out rather than a changewave?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not completely sure, when to use changewave vs escape-hatches. I am inclining to use changewave when msbuild change its behavior and when probability of regression is considerable.
The fact that user requires previous behavior of msbuild does not necessary means he wants to reject perf optimizations as well.
Though I might be looking at it wrong. Please let me know if you prefer to use changewave here.

Copy link
Member

Choose a reason for hiding this comment

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

For a thing like this where we hope it is never needed, I think a changewave is best since they'll "naturally" expire as we follow the policy. I tend to favor explicit switches (usually in addition to a changewave) only if we expect to need the configurability "forever", like in #6560.

@benvillalobos or @marcpopMSFT might have more detailed or different thoughts though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I have moved it under 17_0 change wave.

Copy link
Member

Choose a reason for hiding this comment

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

To add onto rainer's thoughts, if there were backlash such that we know a permanent workaround is needed then we can always add the secondary/permanent escape hatch later. Perhaps as part of the wave "rotating out" when we've gathered more real world data.

@rokonec rokonec self-assigned this Sep 10, 2021
{
// Cache 1st requested configuration section. In unit tests, different Configuration is provided for particular test cases.
// During runtime, however, only MSBuild exe configuration file is provided to read toolset configuration from,
// and modifying MSBuild exe configuration during lifetime of msbuild nodes is neither expected nor supported.
Copy link
Member

Choose a reason for hiding this comment

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

I think this is more supported if someone uses MSBuildLocator to get here, so msbuild.exe.config isn't the exe.config of relevance, and they proceed to use the same (in proc) node to do something else. It still sounds pretty unexpected to me, though.

Copy link
Member

Choose a reason for hiding this comment

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

MSBuild.exe.config should always be the only .exe.config of relevance, even in Locator scenarios.

Copy link
Member

Choose a reason for hiding this comment

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

Didn't we find that with in-proc nodes from Locator, it didn't even know about msbuild.exe.config by default? It was using BuilderApp.exe.config, which I could have modified to fit my scenario.

Copy link
Member

Choose a reason for hiding this comment

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

Ah! There are two things in the app.config:

  1. .NET Framework configuration, such as binding redirects. These are pulled from {TheActualApp}.exe.config.
  2. MSBuild's configuration section, with toolsets and definitions of things like $(MSBuildExtensionsPath). This is always from MSBuild.exe.config and is what is relevant to this PR.

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Sep 10, 2021
@AR-May
Copy link
Member

AR-May commented Sep 13, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AR-May AR-May merged commit ea1d6d9 into dotnet:main Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider caching toolset information in memory
5 participants