-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Test allocations #75171
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a significant source of redundant |
||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using System.Threading; | ||
|
@@ -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[])); | ||
jaredpar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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[])); | ||
jaredpar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a number of tests that call say |
||
{ | ||
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 | ||
|
There was a problem hiding this comment.
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 unnecessarybyte[]
.