msbuild
msbuild copied to clipboard
Consider eliminating ProjectStringCache
ProjectStringCache is used to intern text and whitespace strings parsed from XML project files. It has a manual lifetime mechanism where ref-counted entries are associated with the XML document they came from and then bulk-removed when the last associated document is released.
We should:
- Verify that the cache is still adding value, i.e. that System.Xml is not interning strings for us.
- Check how many strings in this cache later make their way into
OpportunisticIntern, i.e. the overlap between these two caches, and measure the performance impact of eliminatingProjectStringCachein favor ofOpportunisticIntern. - Depending on the outcome of above investigations: Do nothing, or make the XML DOM use
OpportunisticIntern, or remove XML string interning from MSBuild altogether.
We have a custom tool that deals with .sln, using Microsoft.Build - just profiled our app, and 30% of the time is spent there -
| Function Name | Total CPU [unit, %] | Self CPU [unit, %] | Module |
|---|---|---|---|
| | - Microsoft.Build.Construction.ProjectStringCache.Add(string, System.Xml.XmlDocument) | 19568 (31.50%) | 18448 (29.70%) | Microsoft.Build.dll |
wondering if there is a way to disable it? This is from Visual Studio 2019 Professional, 16.11.1.47101
@malkia I'm afraid there is currently no switch to disable the cache. If it's acceptable for you to use a custom build of MSBuild, it is a matter of changing four source lines.
string interned = StringCache.Add(text, this);
should simply become
string interned = text;
(In one case the name of the variable is textNode instead of interned.)