msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Consider eliminating ProjectStringCache

Open ladipro opened this issue 5 years ago • 2 comments

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 eliminating ProjectStringCache in favor of OpportunisticIntern.
  • Depending on the outcome of above investigations: Do nothing, or make the XML DOM use OpportunisticIntern, or remove XML string interning from MSBuild altogether.

ladipro avatar Jun 18 '20 13:06 ladipro

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 avatar Oct 20 '21 20:10 malkia

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

ladipro avatar Oct 21 '21 14:10 ladipro