Skip to content

Custom ILLinker substitutions for feature switches don't seem to work on .NET 8 #88015

Closed

Description

@Sergio0694

Description

I've just enabled proper trimming of custom feature switches in ComputeSharp (Sergio0694/ComputeSharp#532), and wanted to check the difference on .NET 8 as well to see how it compared to .NET 7 with the feature switches set or not. It seems however that they're not really working on .NET 8, for some reason. If I'm doing something wrong, I'm not sure I'm seeing what that is 😅

Note: I'm testing specifically with NativeAOT, didn't check with just trimming without AOT.

Reproduction Steps

  • Checkout to https://github.com/Sergio0694/ComputeSharp/tree/dev/net8.0
  • $env:COMPUTESHARP_SWAPCHAIN_CLI_PUBLISH_AOT='true';
  • dotnet publish samples\ComputeSharp.SwapChain.Cli\ComputeSharp.SwapChain.Cli.csproj -c Release -f net8.0 -r win-x64
  • Check the size of the resulting published binary 1️⃣
  • Open samples\ComputeSharp.SwapChain.Cli\ComputeSharp.SwapChain.Cli.csproj
  • Delete the feature switches at lines 45-49:
<ItemGroup>
  <RuntimeHostConfigurationOption Include="COMPUTESHARP_ENABLE_DEBUG_OUTPUT" Value="false" Trim="true" />
  <RuntimeHostConfigurationOption Include="COMPUTESHARP_ENABLE_DEVICE_REMOVED_EXTENDED_DATA" Value="false" Trim="true" />
  <RuntimeHostConfigurationOption Include="COMPUTESHARP_DISABLE_GPU_TIMEOUT" Value="false" Trim="true" />
</ItemGroup>
  • dotnet publish samples\ComputeSharp.SwapChain.Cli\ComputeSharp.SwapChain.Cli.csproj -c Release -f net8.0 -r win-x64
  • Check the size of the resulting published binary 2️⃣

Expected behavior

I would expect the size of the first binary to be a bit smaller than that of the second binary.
When building with .NET 7, from main, this is exactly what I'm getting.

These are my results on main with .NET 7:

RuntimeHostConfigurationOption-s x64 binary size
Yes 1.643 KB
No 1.710 KB

Getting about 70 KB of binary size savings, which is nice.

Actual behavior

On .NET 8, doing the steps above, I'm getting this:

RuntimeHostConfigurationOption-s x64 binary size
Yes 1.587 KB
No 1.587 KB

...? Have there been any changes around runtime configuration options that I was expected to do? 🤔

Regression?

Would seem so, works as expected on .NET 7.

Configuration

  • Windows 11 Enterprise (x64) 22621.1848
  • 7.0.400-preview.23274.1
  • 8.0.100-preview.7.23325.2

Activity

  1. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jun 25, 2023
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jun 25, 2023
  3. added and removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jun 25, 2023
  4. teo-tsirpanis commented on Jun 25, 2023

    @teo-tsirpanis
    Contributor

    Can you verify through the MSBuild binary log that the configuration options are passed to the linker?

  5. kant2002 commented on Jun 25, 2023

    @kant2002
    Contributor

    The ILLink target no longer run

    This was introduced in #63914

  6. filipnavara commented on Jun 25, 2023

    @filipnavara
    Member

    The ILLink target no longer run

    The switches are interpreted by ILCompiler though and there should be parity in the observed behavior.

  7. Sergio0694 commented on Jun 25, 2023

    @Sergio0694
    ContributorAuthor

    Also — that PR (#63914) seems to have been merged in January 2022, so wouldn't that be in .NET 7 as well? 🤔

  8. added this to the Future milestone on Jun 26, 2023
  9. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 26, 2023
  10. MichalStrehovsky commented on Jun 26, 2023

    @MichalStrehovsky
    Member

    This should work (we have tests and we rely on this working in many places) but either the resource is not embedded properly, the XML is not correct, or the switch is not getting passed to the compiler. I always need to debug the compiler whenever I do something with these XMLs because the format and mechanism is inscrutable. This is not a publicly supported mechanism because the developer experience around this mechanism is horrible and not self-serviceable. Moving to future.

  11. Sergio0694 commented on Jun 26, 2023

    @Sergio0694
    ContributorAuthor

    Ok well, this was indeed just my fault — I had forgotten to update the MSBuild condition for .NET 8, so the ILLinker.Substitutions.xml file was not being embedded on that branch, as it was still just checking for .NET 6 😅

    Re-did the tests after fixing that and I can confirm it works just fine, and saves ~73 KB 😄

  12. ghost locked as resolved and limited conversation to collaborators on Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions