You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SkipLocalsInit condition applies to NetCoreAppCurrent only #54964
<SkipLocalsInitCondition="'$(SkipLocalsInit)' == '' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IsNETCoreAppSrc)' == 'true' and ($([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)')))">true</SkipLocalsInit>
The SkipLocalsInit property is conditioned on NetCoreAppCurrent inbox assets only. Some packages contain both inbox and OOB assets. These optimization will be lost for net6.0 when NetCoreAppCurrent means net7.0 and new packages will be released.
One option would be to support SkipLocalsInit on all .NETCoreApp tfms. Another option would be to not apply SkipLocalsInit to assets that ship in packages as well but which would cause a perf regression.
The SkipLocalsInit property is conditioned on NetCoreAppCurrent inbox assets only
This correctly reflects the original intent. We audited the libs in the shared framework; we didn't do so for OOBs.
Some packages contain both inbox and OOB assets.
Can you elaborate on that? What does it mean for a package to contain an inbox asset?
One option would be to support SkipLocalsInit on all .NETCoreApp tfms.
We would need to go through all of our assets that this would apply to, in particular ones with stackallocs, P/Invokes, and in general unsafe code, and make sure everything is sufficiently protected.
Another option would be to not apply SkipLocalsInit to assets that ship in packages as well but which would cause a perf regression.
This is where we should start, and then opt things in as we find opportunities / meaningful improvements.
Can you elaborate on that? What does it mean for a package to contain an inbox asset?
I believe that what @ViktorHofer meant here, is that there are some inbox assets that also get shipped via its library's OOB package, for example System.Text.Json. It's net6.0 asset ships inbox, but also gets shipped in the System.Text.Json package since we want to be able to replace it if we want to via the package, and I can see how @ViktorHofer concern is valid in case we were shipping a slightly different asset inbox than the OOB one. That said, I believe that is not the case here, as if I understand correctly then the OOB asset should also use SkipLocalsInit as the "IsNETCoreAppSrc" condition will still evaluate to true.
@ViktorHofer given the answers from @stephentoub above, are there still concerns with the way this feature works today? If not, let's move this issue out of 6.0.0 in order to track in the future the work to try to enable the feature for assets targeting older frameworks.
Can you elaborate on that? What does it mean for a package to contain an inbox asset?
6.0 packages produced in dotnet/runtime contain net6.0 assets even if those ship as part of a shared framework. One example of that is System.Text.Json. During a build, conflict resolution which is part of the sdk trims out assets which are satisfied by the shared framework. Conflict resolution takes the PlatformManifest which lists all assemblies including their assembly and file versions as an input and compares them against references which are added i.e. via a package.
In the event of servicing, a change in System.Text.Json is delivered via the shared framework and/or via the updated System.Text.Json package. Conflict resolution will make sure that the best compatible asset is chosen.
This correctly reflects the original intent. We audited the libs in the shared framework; we didn't do so for OOBs.
Consider the 7.0 package of System.Text.Json which will include both the net6.0 asset as well as the net7.0 asset (according to our package support policy). With the current condition:
<SkipLocalsInit Condition="'$(SkipLocalsInit)' == '' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IsNETCoreAppSrc)' == 'true' and ($([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)')))">true</SkipLocalsInit>
SkipLocalsInit is only applied to $(NetCoreAppCurrent) which maps to net7.0 when producing a 7.0 package. As the net6.0 asset is live built as well, it will loose the SkipLocalsInit optimization which it received when $(NetCoreAppCurrent) mapped to net6.0.
My assumption is that we don't want to regress the previous shipped asset by changing the SkipLocalsInit condition to:
<SkipLocalsInit Condition="'$(SkipLocalsInit)' == '' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IsNETCoreAppSrc)' == 'true'">true</SkipLocalsInit>
That way the optimization will still only apply to assemblies which are part of the shared framework but for both the current release and previous releases.
; Program.GetValue(System.Nullable`1<Int32>)subrsp,28mov[rsp+38],rdxmovzxeax,byte ptr [rsp+38]testeax,eaxje short M01_L00testeax,eaxje short M01_L01moveax,[rsp+3C]addrsp,28retM01_L00:moveax,0FFFFFFFFaddrsp,28retM01_L01:call System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_NoValue()int3; Total bytes of code 47
.NET 6:
; Program.GetValue(System.Nullable`1<Int32>)mov[rsp+10],rdxcmp byte ptr [rsp+10],0je short M01_L00moveax,[rsp+14]retM01_L00:moveax,0FFFFFFFFret; Total bytes of code 23
Retargeting to 7.0 as the remaining work is main specific. After #57844 is in, this will be a matter of updating the condition and removing the last and ... part.
Activity
stephentoub commentedon Jun 30, 2021
This correctly reflects the original intent. We audited the libs in the shared framework; we didn't do so for OOBs.
Can you elaborate on that? What does it mean for a package to contain an inbox asset?
We would need to go through all of our assets that this would apply to, in particular ones with stackallocs, P/Invokes, and in general unsafe code, and make sure everything is sufficiently protected.
This is where we should start, and then opt things in as we find opportunities / meaningful improvements.
joperezr commentedon Aug 5, 2021
I believe that what @ViktorHofer meant here, is that there are some inbox assets that also get shipped via its library's OOB package, for example System.Text.Json. It's net6.0 asset ships inbox, but also gets shipped in the System.Text.Json package since we want to be able to replace it if we want to via the package, and I can see how @ViktorHofer concern is valid in case we were shipping a slightly different asset inbox than the OOB one. That said, I believe that is not the case here, as if I understand correctly then the OOB asset should also use SkipLocalsInit as the "IsNETCoreAppSrc" condition will still evaluate to true.
@ViktorHofer given the answers from @stephentoub above, are there still concerns with the way this feature works today? If not, let's move this issue out of 6.0.0 in order to track in the future the work to try to enable the feature for assets targeting older frameworks.
ViktorHofer commentedon Aug 20, 2021
6.0 packages produced in dotnet/runtime contain net6.0 assets even if those ship as part of a shared framework. One example of that is System.Text.Json. During a build, conflict resolution which is part of the sdk trims out assets which are satisfied by the shared framework. Conflict resolution takes the PlatformManifest which lists all assemblies including their assembly and file versions as an input and compares them against references which are added i.e. via a package.
In the event of servicing, a change in System.Text.Json is delivered via the shared framework and/or via the updated System.Text.Json package. Conflict resolution will make sure that the best compatible asset is chosen.
Consider the 7.0 package of System.Text.Json which will include both the net6.0 asset as well as the net7.0 asset (according to our package support policy). With the current condition:
<SkipLocalsInit Condition="'$(SkipLocalsInit)' == '' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IsNETCoreAppSrc)' == 'true' and ($([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)')))">true</SkipLocalsInit>SkipLocalsInitis only applied to$(NetCoreAppCurrent)which maps to net7.0 when producing a 7.0 package. As the net6.0 asset is live built as well, it will loose theSkipLocalsInitoptimization which it received when$(NetCoreAppCurrent)mapped to net6.0.My assumption is that we don't want to regress the previous shipped asset by changing the
SkipLocalsInitcondition to:<SkipLocalsInit Condition="'$(SkipLocalsInit)' == '' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IsNETCoreAppSrc)' == 'true'">true</SkipLocalsInit>That way the optimization will still only apply to assemblies which are part of the shared framework but for both the current release and previous releases.
stephentoub commentedon Aug 20, 2021
Yes, if that's what's going to happen, we should fix that.
stephentoub commentedon Aug 20, 2021
.NET 5:
.NET 6:
8 remaining items
ViktorHofer commentedon Aug 20, 2021
Adding the issue back to 6.0 as I believe this needs to be fixed in both main and release/6.0-rc1.
Don't regress SkipLocalsInit optimization on net5.0 assets
[release/6.0] Don't regress SkipLocalsInit optimization on < 6.0 .NET…
ViktorHofer commentedon Aug 23, 2021
Retargeting to 7.0 as the remaining work is main specific. After #57844 is in, this will be a matter of updating the condition and removing the last
and ...part.Don't regress SkipLocalsInit optimization on <= NET6
Don't regress SkipLocalsInit optimization on <= NET6 (#59797)