From 22299f788601bbe3b8e2e86ae48c477e2ab95c61 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 17 May 2024 11:21:40 -0700 Subject: [PATCH] Delete DebugSymbols This property does not do what its name says. The symbols are generated regardless of whether this property is true or false. What this property actually does is that it disables C# peephole IL optimizations. This change results in ~0.5% IL binary size improvement thanks to the Roslyn IL peephole optimizations that it enables. --- Directory.Build.props | 1 - eng/illink.targets | 2 +- src/coreclr/nativeaot/Directory.Build.props | 1 - .../Decoding/SignatureDecoderTests.cs | 4 ++++ .../System/Reflection/MethodBaseTests.cs | 6 ++++++ .../System/Reflection/MethodBodyTests.cs | 19 +++++++++++++------ .../InlineArray/InlineArrayInvalid.csproj | 2 ++ .../classloader/RefFields/Validate.csproj | 2 ++ .../InvalidOperations.csproj | 2 ++ 9 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index b374f83f816ea..4107aab1da083 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -390,7 +390,6 @@ $(NoWarn),CS8969 portable - true true false diff --git a/eng/illink.targets b/eng/illink.targets index 0dca1cd421991..b15611bbf1dd4 100644 --- a/eng/illink.targets +++ b/eng/illink.targets @@ -34,7 +34,7 @@ false - true + true $(IntermediateOutputPath)ILLink.Resources.Substitutions.xml true diff --git a/src/coreclr/nativeaot/Directory.Build.props b/src/coreclr/nativeaot/Directory.Build.props index d3277aa58ece7..b06c29baeb43e 100644 --- a/src/coreclr/nativeaot/Directory.Build.props +++ b/src/coreclr/nativeaot/Directory.Build.props @@ -13,7 +13,6 @@ $(NetCoreAppCurrent) Portable - true $(RuntimeBinDir)/aotsdk/ Debug;Release;Checked diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs index 7570404923a7a..bcb6661e6ef2c 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs @@ -278,10 +278,14 @@ public static class PinnedAndUnpinnedLocalsToDecode public static unsafe int DoSomething() { byte[] bytes = new byte[] { 1, 2, 3 }; + Keep(ref bytes); fixed (byte* bytePtr = bytes) { return *bytePtr; } + + // Reference local variables to prevent them from being optimized out by Roslyn + static void Keep(ref T value) { }; } } diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs index eeda2341e251d..9d69ce855c6a4 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs @@ -113,12 +113,18 @@ private static int MyOtherMethod(int x) public static void MyOtherMethod(object arg) { int var1 = 2; + Keep(ref var1); + string var2 = "I am a string"; + Keep(ref var2); if (arg == null) { throw new ArgumentNullException("Input arg cannot be null."); } + + // Reference local variables to prevent them from being optimized out by Roslyn + static void Keep(ref T value) { }; } #pragma warning restore xUnit1013 // Public method should be marked as test diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs index 146baf023bbfe..eb6f4b36fab9d 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs @@ -41,10 +41,10 @@ public static void Test_MethodBody_ExceptionHandlingClause() if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter) { Assert.Equal(typeof(Exception), ehc.CatchType); - Assert.Equal(19, ehc.HandlerLength); - Assert.Equal(70, ehc.HandlerOffset); + Assert.Equal(27, ehc.HandlerLength); + Assert.Equal(86, ehc.HandlerOffset); Assert.Equal(61, ehc.TryLength); - Assert.Equal(9, ehc.TryOffset); + Assert.Equal(25, ehc.TryOffset); return; } } @@ -64,10 +64,10 @@ public static void Test_MethodBody_ExceptionHandlingClause() if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter) { Assert.Equal(typeof(Exception), ehc.CatchType); - Assert.Equal(14, ehc.HandlerLength); - Assert.Equal(58, ehc.HandlerOffset); + Assert.Equal(21, ehc.HandlerLength); + Assert.Equal(72, ehc.HandlerOffset); Assert.Equal(50, ehc.TryLength); - Assert.Equal(8, ehc.TryOffset); + Assert.Equal(22, ehc.TryOffset); return; } } @@ -79,7 +79,10 @@ public static void Test_MethodBody_ExceptionHandlingClause() private static void MethodBodyExample(object arg) { int var1 = 2; + Keep(ref var1); + string var2 = "I am a string"; + Keep(ref var2); try { @@ -94,6 +97,7 @@ private static void MethodBodyExample(object arg) } catch (Exception ex) { + Keep(ref ex); Console.WriteLine(ex.Message); } finally @@ -101,6 +105,9 @@ private static void MethodBodyExample(object arg) var1 = 3; var2 = "I am a new string!"; } + + // Reference local variables to prevent them from being optimized out by Roslyn + static void Keep(ref T value) { }; } } } diff --git a/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj b/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj index 8323d950dff73..098ebbb26a691 100644 --- a/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj +++ b/src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj @@ -3,6 +3,8 @@ true true + + false diff --git a/src/tests/Loader/classloader/RefFields/Validate.csproj b/src/tests/Loader/classloader/RefFields/Validate.csproj index f8e94ce317a33..8d5547ca7cf09 100644 --- a/src/tests/Loader/classloader/RefFields/Validate.csproj +++ b/src/tests/Loader/classloader/RefFields/Validate.csproj @@ -4,6 +4,8 @@ true true true + + false diff --git a/src/tests/baseservices/invalid_operations/InvalidOperations.csproj b/src/tests/baseservices/invalid_operations/InvalidOperations.csproj index 5f4c03e91ae11..1c5f1bf800139 100644 --- a/src/tests/baseservices/invalid_operations/InvalidOperations.csproj +++ b/src/tests/baseservices/invalid_operations/InvalidOperations.csproj @@ -3,6 +3,8 @@ true true + + false