Skip to content

Commit

Permalink
[Crossgen2] Improve compilation throughput for types with many fields (
Browse files Browse the repository at this point in the history
…#43195)

`IsLayoutFixedInCurrentVersionBubble` is a fairly expensive algorithm and can be called very frequently for the same type during JIT compilation. Store the computed result so future lookups are fast.

Fixes #38259
  • Loading branch information
nattress authored Oct 12, 2020
1 parent 16ba8b4 commit 1e95768
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -236,6 +237,11 @@ public sealed class ReadyToRunCodegenCompilation : Compilation
public ReadyToRunSymbolNodeFactory SymbolNodeFactory { get; }
public ReadyToRunCompilationModuleGroupBase CompilationModuleGroup { get; }
private readonly int? _customPESectionAlignment;
/// <summary>
/// Determining whether a type's layout is fixed is a little expensive and the question can be asked many times
/// for the same type during compilation so preserve the computed value.
/// </summary>
private ConcurrentDictionary<TypeDesc, bool> _computedFixedLayoutTypes = new ConcurrentDictionary<TypeDesc, bool>();

internal ReadyToRunCodegenCompilation(
DependencyAnalyzerBase<NodeFactory> dependencyGraph,
Expand Down Expand Up @@ -375,7 +381,7 @@ public override void WriteDependencyLog(string outputFileName)
}
}

public bool IsLayoutFixedInCurrentVersionBubble(TypeDesc type)
private bool IsLayoutFixedInCurrentVersionBubbleInternal(TypeDesc type)
{
// Primitive types and enums have fixed layout
if (type.IsPrimitive || type.IsEnum)
Expand Down Expand Up @@ -423,6 +429,9 @@ public bool IsLayoutFixedInCurrentVersionBubble(TypeDesc type)
return true;
}

public bool IsLayoutFixedInCurrentVersionBubble(TypeDesc type) =>
_computedFixedLayoutTypes.GetOrAdd(type, (t) => IsLayoutFixedInCurrentVersionBubbleInternal(t));

public bool IsInheritanceChainLayoutFixedInCurrentVersionBubble(TypeDesc type)
{
// This method is not expected to be called for value types
Expand Down
3 changes: 0 additions & 3 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/clr-x64-JIT/v4.0/devdiv374539/DevDiv_374539/*">
<Issue>https://github.com/dotnet/runtime/issues/32732</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/CLR-x86-JIT/V2.0-Beta2/b399444/**/*">
<Issue>https://github.com/dotnet/runtime/issues/38259</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/CLR-x86-JIT/v2.1/DDB/B168384/LdfldaHack/*">
<Issue>https://github.com/dotnet/runtime/issues/615</Issue>
</ExcludeList>
Expand Down

0 comments on commit 1e95768

Please sign in to comment.