Skip to content

Commit 81de82f

Browse files
authored
Reduce LOH allocations in MetadataWriter (#78245)
MetadataWriter's use of Dictionary leads to LOH allocations in the Roslyn CA process. Instead, switch over to SegmentedDictionary to reduce that pressure. From the Roslyn C# completion speedometer test, about 16% of all LOH allocations occur adding to MetadataWriter._signatureIndex. This type represents the 2nd highest entry on the LOH list. After changing to a SegmentedDictionary these LOH are no longer present. See PR for images depicting the before/after allocations.
1 parent f4ba25f commit 81de82f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Compilers/Core/Portable/PEWriter/MetadataWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected MetadataWriter(
111111

112112
// EDMAURER provide some reasonable size estimates for these that will avoid
113113
// much of the reallocation that would occur when growing these from empty.
114-
_signatureIndex = new Dictionary<ISignature, KeyValuePair<BlobHandle, ImmutableArray<byte>>>(module.HintNumberOfMethodDefinitions, ReferenceEqualityComparer.Instance); //ignores field signatures
114+
_signatureIndex = new SegmentedDictionary<ISignature, KeyValuePair<BlobHandle, ImmutableArray<byte>>>(module.HintNumberOfMethodDefinitions, ReferenceEqualityComparer.Instance); //ignores field signatures
115115

116116
this.Context = context;
117117
this.messageProvider = messageProvider;
@@ -443,7 +443,7 @@ private bool IsMinimalDelta
443443
private readonly Dictionary<IFieldReference, BlobHandle> _fieldSignatureIndex = new Dictionary<IFieldReference, BlobHandle>(ReferenceEqualityComparer.Instance);
444444

445445
// We need to keep track of both the index of the signature and the actual blob to support VB static local naming scheme.
446-
private readonly Dictionary<ISignature, KeyValuePair<BlobHandle, ImmutableArray<byte>>> _signatureIndex;
446+
private readonly SegmentedDictionary<ISignature, KeyValuePair<BlobHandle, ImmutableArray<byte>>> _signatureIndex;
447447

448448
private readonly Dictionary<IMarshallingInformation, BlobHandle> _marshallingDescriptorIndex = new Dictionary<IMarshallingInformation, BlobHandle>();
449449
protected readonly List<MethodImplementation> methodImplList = new List<MethodImplementation>();

0 commit comments

Comments
 (0)