Skip to content

Commit 153a94b

Browse files
Delete DebugSymbols=true setting for the repo build (#102392)
* 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. * Update eng/illink.targets Co-authored-by: Michal Strehovský <[email protected]> --------- Co-authored-by: Michal Strehovský <[email protected]>
1 parent 68f3edc commit 153a94b

File tree

9 files changed

+31
-10
lines changed

9 files changed

+31
-10
lines changed

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@
390390
<NoWarn>$(NoWarn),CS8969</NoWarn>
391391
<!-- Always pass portable to override arcade sdk which uses embedded for local builds -->
392392
<DebugType>portable</DebugType>
393-
<DebugSymbols>true</DebugSymbols>
394393
<KeepNativeSymbols Condition="'$(KeepNativeSymbols)' == '' and '$(DotNetBuildSourceOnly)' == 'true'">true</KeepNativeSymbols>
395394
<KeepNativeSymbols Condition="'$(KeepNativeSymbols)' == ''">false</KeepNativeSymbols>
396395
<!-- Used for launchSettings.json and runtime config files. -->

eng/illink.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<!-- Only run the trim analyzer on libraries which have been annotated. -->
3434
<EnableTrimAnalyzer Condition="'$(EnableTrimAnalyzer)' == '' And (Exists('$(ILLinkSuppressionsXml)') Or Exists('$(ILLinkSuppressionsConfigurationSpecificXml)'))">false</EnableTrimAnalyzer>
3535

36-
<!-- if building a PDB, tell illink to rewrite the symbols file -->
37-
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == '' and '$(DebugSymbols)' != 'false'">true</ILLinkRewritePDBs>
36+
<!-- tell illink to rewrite the symbols file -->
37+
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == ''">true</ILLinkRewritePDBs>
3838

3939
<ILLinkResourcesSubstitutionIntermediatePath>$(IntermediateOutputPath)ILLink.Resources.Substitutions.xml</ILLinkResourcesSubstitutionIntermediatePath>
4040
<GenerateResourcesSubstitutions Condition="'$(GenerateResourcesSubstitutions)' == '' and '$(StringResourcesPath)' != ''">true</GenerateResourcesSubstitutions>

src/coreclr/nativeaot/Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
1414

1515
<DebugType>Portable</DebugType>
16-
<DebugSymbols>true</DebugSymbols>
1716

1817
<OutputPath Condition="$(MSBuildProjectName.StartsWith('System.Private.'))">$(RuntimeBinDir)/aotsdk/</OutputPath>
1918
<Configurations>Debug;Release;Checked</Configurations>

src/libraries/System.Reflection.Metadata/tests/Metadata/Decoding/SignatureDecoderTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,14 @@ public static class PinnedAndUnpinnedLocalsToDecode
278278
public static unsafe int DoSomething()
279279
{
280280
byte[] bytes = new byte[] { 1, 2, 3 };
281+
Keep(ref bytes);
281282
fixed (byte* bytePtr = bytes)
282283
{
283284
return *bytePtr;
284285
}
286+
287+
// Reference local variables to prevent them from being optimized out by Roslyn
288+
static void Keep<T>(ref T value) { };
285289
}
286290
}
287291

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBaseTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,18 @@ private static int MyOtherMethod(int x)
113113
public static void MyOtherMethod(object arg)
114114
{
115115
int var1 = 2;
116+
Keep(ref var1);
117+
116118
string var2 = "I am a string";
119+
Keep(ref var2);
117120

118121
if (arg == null)
119122
{
120123
throw new ArgumentNullException("Input arg cannot be null.");
121124
}
125+
126+
// Reference local variables to prevent them from being optimized out by Roslyn
127+
static void Keep<T>(ref T value) { };
122128
}
123129
#pragma warning restore xUnit1013 // Public method should be marked as test
124130

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/MethodBodyTests.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
4141
if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter)
4242
{
4343
Assert.Equal(typeof(Exception), ehc.CatchType);
44-
Assert.Equal(19, ehc.HandlerLength);
45-
Assert.Equal(70, ehc.HandlerOffset);
44+
Assert.Equal(27, ehc.HandlerLength);
45+
Assert.Equal(86, ehc.HandlerOffset);
4646
Assert.Equal(61, ehc.TryLength);
47-
Assert.Equal(9, ehc.TryOffset);
47+
Assert.Equal(25, ehc.TryOffset);
4848
return;
4949
}
5050
}
@@ -64,10 +64,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
6464
if (ehc.Flags != ExceptionHandlingClauseOptions.Finally && ehc.Flags != ExceptionHandlingClauseOptions.Filter)
6565
{
6666
Assert.Equal(typeof(Exception), ehc.CatchType);
67-
Assert.Equal(14, ehc.HandlerLength);
68-
Assert.Equal(58, ehc.HandlerOffset);
67+
Assert.Equal(21, ehc.HandlerLength);
68+
Assert.Equal(72, ehc.HandlerOffset);
6969
Assert.Equal(50, ehc.TryLength);
70-
Assert.Equal(8, ehc.TryOffset);
70+
Assert.Equal(22, ehc.TryOffset);
7171
return;
7272
}
7373
}
@@ -79,7 +79,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
7979
private static void MethodBodyExample(object arg)
8080
{
8181
int var1 = 2;
82+
Keep(ref var1);
83+
8284
string var2 = "I am a string";
85+
Keep(ref var2);
8386

8487
try
8588
{
@@ -94,13 +97,17 @@ private static void MethodBodyExample(object arg)
9497
}
9598
catch (Exception ex)
9699
{
100+
Keep(ref ex);
97101
Console.WriteLine(ex.Message);
98102
}
99103
finally
100104
{
101105
var1 = 3;
102106
var2 = "I am a new string!";
103107
}
108+
109+
// Reference local variables to prevent them from being optimized out by Roslyn
110+
static void Keep<T>(ref T value) { };
104111
}
105112
}
106113
}

src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
44
<RequiresProcessIsolation>true</RequiresProcessIsolation>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
7+
<Optimize>false</Optimize>
68
</PropertyGroup>
79
<ItemGroup>
810
<Compile Include="InlineArrayInvalid.cs" />

src/tests/Loader/classloader/RefFields/Validate.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<RequiresProcessIsolation>true</RequiresProcessIsolation>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
66
<MonoAotIncompatible>true</MonoAotIncompatible>
7+
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
8+
<Optimize>false</Optimize>
79
</PropertyGroup>
810
<ItemGroup>
911
<Compile Include="Validate.cs" />

src/tests/baseservices/invalid_operations/InvalidOperations.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
44
<RequiresProcessIsolation>true</RequiresProcessIsolation>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
<!-- Make sure that invalid operations are not optimized out by Roslyn -->
7+
<Optimize>false</Optimize>
68
</PropertyGroup>
79
<ItemGroup>
810
<Compile Include="ManagedPointers.cs" />

0 commit comments

Comments
 (0)