Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test allocations #75171

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12384,7 +12384,7 @@ void binaryOperator(string op, string leftType, string rightType, string expecte

if (expectedDiagnostics.Length == 0)
{
CompileAndVerify(comp);
CompileAndVerify(comp, emitOptions: EmitOptions.Default);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default CompileAndVerify embeds portable PDBs and the sheer number of tests here was causing that allocate 100MB of unnecessary byte[].

}

static bool useUnsafe(string type) => type == "void*";
Expand Down
13 changes: 7 additions & 6 deletions src/Compilers/Test/Core/Platform/Desktop/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a significant source of redundant byte[] allocations.

using System.Runtime.Serialization;
using System.Text;
using System.Threading;
Expand All @@ -30,27 +31,27 @@ public static void AddArray<T>(this SerializationInfo info, string name, Immutab
// we will copy the content into an array and serialize the copy
// we could serialize element-wise, but that would require serializing
// name and type for every serialized element which seems worse than creating a copy.
info.AddValue(name, value.IsDefault ? null : value.ToArray(), typeof(T[]));
info.AddValue(name, value.IsDefault ? null : ImmutableCollectionsMarshal.AsArray(value), typeof(T[]));
}

public static ImmutableArray<T> GetArray<T>(this SerializationInfo info, string name) where T : class
{
var arr = (T[])info.GetValue(name, typeof(T[]));
return ImmutableArray.Create<T>(arr);
var array = (T[])info.GetValue(name, typeof(T[]));
return ImmutableCollectionsMarshal.AsImmutableArray(array);
}

public static void AddByteArray(this SerializationInfo info, string name, ImmutableArray<byte> value)
{
// we will copy the content into an array and serialize the copy
// we could serialize element-wise, but that would require serializing
// name and type for every serialized element which seems worse than creating a copy.
info.AddValue(name, value.IsDefault ? null : value.ToArray(), typeof(byte[]));
info.AddValue(name, value.IsDefault ? null : ImmutableCollectionsMarshal.AsArray(value), typeof(byte[]));
}

public static ImmutableArray<byte> GetByteArray(this SerializationInfo info, string name)
{
var arr = (byte[])info.GetValue(name, typeof(byte[]));
return ImmutableArray.Create<byte>(arr);
var array = (byte[])info.GetValue(name, typeof(byte[]));
return ImmutableCollectionsMarshal.AsImmutableArray(array);
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/Compilers/Test/Core/TargetFrameworkUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,26 @@ public static class NetCoreApp
/// </summary>
public static class NetFramework
{
private static ImmutableArray<MetadataReference> s_references;

/// <summary>
/// This is the full set of references provided by default on the .NET Framework TFM
/// </summary>
/// <remarks>
/// Need to special case tuples until we move to net472
/// </remarks>
public static ImmutableArray<MetadataReference> References { get; } = [.. Net461.References.All, Net461.ExtraReferences.SystemValueTuple];
public static ImmutableArray<MetadataReference> References
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of tests that call say NetFramework.mscorlib. When this was a static initializer that realized all these values when they didn't really need to be. This is only a savings in certain silces of our tests but it's a significant one in them.

{
get
{
if (s_references.IsDefault)
{
s_references = [.. Net461.References.All, Net461.ExtraReferences.SystemValueTuple];
}

return s_references;
}
}

/// <summary>
/// This is a limited set of references on this .NET Framework TFM. This should be avoided in new code
Expand Down
Loading