Skip to content

Commit

Permalink
WIP - Add Json feature switch to remove Ref.Emit code.
Browse files Browse the repository at this point in the history
Contributes to dotnet#38693
  • Loading branch information
eerhardt committed May 11, 2021
1 parent 138b73e commit 59c60c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<linker>
<assembly fullname="System.Text.Json">
<type fullname="System.Text.Json.JsonSerializerOptions">
<method signature="System.Boolean get_MinSizeOpts()" body="stub" value="true" feature="System.Text.Json.MinSizeOpts" featurevalue="true" />
</type>
</assembly>
</linker>
8 changes: 7 additions & 1 deletion src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;netcoreapp3.0;net461</TargetFrameworks>
Expand All @@ -19,6 +19,12 @@
<!-- Use the contract reference path for ApiCompat. -->
<ContractTargetFramework Condition="'$(TargetFramework)' == 'netcoreapp3.0'">netstandard2.0</ContractTargetFramework>
</PropertyGroup>
<PropertyGroup>
<ILLinkDirectory>$(MSBuildThisFileDirectory)ILLink\</ILLinkDirectory>
</PropertyGroup>
<ItemGroup>
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CommonPath)System\HexConverter.cs" Link="Common\System\HexConverter.cs" />
<Compile Include="$(CommonPath)System\Text\Json\PooledByteBufferWriter.cs" Link="Common\System\Text\Json\PooledByteBufferWriter.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public sealed partial class JsonSerializerOptions

internal static readonly JsonSerializerOptions s_defaultOptions = new JsonSerializerOptions();

private static bool MinSizeOpts { get; } =
AppContext.TryGetSwitch("System.Text.Json.MinSizeOpts", out bool minSizeOpts) ? minSizeOpts : false;

private readonly ConcurrentDictionary<Type, JsonTypeInfo> _classes = new ConcurrentDictionary<Type, JsonTypeInfo>();

// Simple LRU cache for the public (de)serialize entry points that avoid some lookups in _classes.
Expand Down Expand Up @@ -560,7 +563,14 @@ internal MemberAccessor MemberAccessorStrategy
if (_memberAccessorStrategy == null)
{
#if NETFRAMEWORK || NETCOREAPP
_memberAccessorStrategy = new ReflectionEmitMemberAccessor();
if (MinSizeOpts)
{
_memberAccessorStrategy = new ReflectionMemberAccessor();
}
else
{
_memberAccessorStrategy = new ReflectionEmitMemberAccessor();
}
#else
_memberAccessorStrategy = new ReflectionMemberAccessor();
#endif
Expand Down

0 comments on commit 59c60c6

Please sign in to comment.