Skip to content

Commit

Permalink
Improve string builder caches (#7093)
Browse files Browse the repository at this point in the history
* Move string builder caches into Framework
* Capacity bracketing
* Enlarge StrignBuilderCache MAX_BUILDER_SIZE
* ReuseableStringBuilder balance diagnostics
  • Loading branch information
rokonec committed Dec 2, 2021
1 parent 93e4693 commit 56ac537
Show file tree
Hide file tree
Showing 14 changed files with 416 additions and 352 deletions.
Expand Up @@ -77,9 +77,6 @@
<Compile Include="..\Shared\FileUtilitiesRegex.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="..\Shared\StringBuilderCache.cs">
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>
<Compile Include="..\Shared\ExceptionHandling.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down
4 changes: 0 additions & 4 deletions src/Build/Microsoft.Build.csproj
Expand Up @@ -99,9 +99,6 @@
<Compile Include="..\Shared\ReadOnlyEmptyCollection.cs">
<Link>Collections\ReadOnlyEmptyCollection.cs</Link>
</Compile>
<Compile Include="..\Shared\StringBuilderCache.cs">
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>
<Compile Include="..\Shared\BufferedReadStream.cs" />
<Compile Include="..\Shared\TaskHostConfiguration.cs" />
<Compile Include="..\Shared\TaskHostTaskCancelled.cs" />
Expand Down Expand Up @@ -140,7 +137,6 @@
<Compile Include="..\Shared\TaskEngineAssemblyResolver.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="..\Shared\ReuseableStringBuilder.cs" />
<Compile Include="..\Shared\ThreadPoolExtensions.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="BackEnd\BuildManager\BuildManager.cs" />
Expand Down
Expand Up @@ -41,7 +41,6 @@
<Compile Include="..\Shared\BuildEnvironmentHelper.cs" />
<Compile Include="..\Shared\ResourceUtilities.cs" />
<Compile Include="..\Shared\ExceptionHandling.cs" />
<Compile Include="..\Shared\StringBuilderCache.cs" />
<Compile Include="..\Shared\FileUtilitiesRegex.cs" />
<Compile Include="..\Shared\UnitTests\AssemblyResources.cs" />
</ItemGroup>
Expand Down
31 changes: 30 additions & 1 deletion src/Framework/MSBuildEventSource.cs
Expand Up @@ -490,6 +490,35 @@ public void CachedSdkResolverServiceResolveSdkStop(string sdkName, string soluti
WriteEvent(67, sdkName, solutionPath, projectPath, success);
}

#endregion
/// <remarks>
/// This events are quite frequent so they are collected by Debug binaries only.
/// </remarks>
[Event(68, Keywords = Keywords.All)]
public void ReusableStringBuilderFactoryStart(int hash, int newCapacity, int oldCapacity, string type)
{
WriteEvent(68, hash, newCapacity, oldCapacity, type);
}

/// <remarks>
/// This events are quite frequent so they are collected by Debug binaries only.
/// </remarks>
[Event(69, Keywords = Keywords.All)]
public void ReusableStringBuilderFactoryStop(int hash, int returningCapacity, int returningLength, string type)
{
WriteEvent(69, hash, returningCapacity, returningLength, type);
}

/// <remarks>
/// As oppose to other ReusableStringBuilderFactory events this one is expected to happens very un-frequently
/// and if it is seen more than 100x per build it might indicates wrong usage patterns resulting into degrading
/// efficiency of ReusableStringBuilderFactory. Hence it is collected in release build as well.
/// </remarks>
[Event(70, Keywords = Keywords.All)]
public void ReusableStringBuilderFactoryUnbalanced(int oldHash, int newHash)
{
WriteEvent(70, oldHash, newHash);
}

#endregion
}
}

0 comments on commit 56ac537

Please sign in to comment.