Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] Properly implement System.Linq.Expressions substitutions according to the recent refactoring #89638

Merged

Conversation

ivanpovazan
Copy link
Member

@ivanpovazan ivanpovazan commented Jul 28, 2023

#89308 introduced a regression for NativeAOT because the changes assumed that ILC trimming can propagate constants over methods. As this is not true, the Ref.Emit backend is not trimmed away by ILC anymore increasing the app size.

This PR fixes this regression, by adjusting the System.Linq.Expressions substitutions to wire DynamicCodeSupported feature switch value to get_CanCompileToIL and get_CanCreateArbitraryDelegates and substitute them with false - avoiding the constant propagation over methods limitation.

Additionally, I cleaned up a few places that had left overs of the removed private feature switches.

Verified that the regression has been fixed by adding a reference to System.Linq.Expressions in the HelloiOS sample and AOTing with and without changes in the PR:

HelloiOS sample main this PR
Size on disk (Mb) 53,3 12,14

Thanks @vitek-karas for figuring out the right approach.

@dotnet/ilc-contrib


Fixes #89527

@ghost
Copy link

ghost commented Jul 28, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

#89308 introduced a regression for NativeAOT because the changes assumed that ILC trimming can propagate constants over methods. As this is not true, the Ref.Emit backend is not trimmed away by ILC anymore increasing the app size.

This PR fixes this regression, by adjusting the System.Linq.Expressions substitutions to wire DynamicCodeSupported feature switch value to get_CanCompileToIL and get_CanCreateArbitraryDelegates and substitute them with false - avoiding the constant propagation over methods limitation.

Additionally, I cleaned up a few places that had left overs of the removed private feature switches.

Thanks @vitek-karas for figuring out the right approach.

@dotnet/ilc-contrib


Fixes #89527

Author: ivanpovazan
Assignees: ivanpovazan
Labels:

area-NativeAOT-coreclr

Milestone: -

@ivanpovazan
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ivanpovazan
Copy link
Member Author

@eerhardt I have measured the impact of this change with https://github.com/aspnet/Benchmarks/tree/main/src/BenchmarksApps/TodosApi on osx-arm64 comparing the main branch and this PR, with dotnet sdk version: 8.0.100-preview.7.23364.32 and locally built framework and ILCompiler packages referenced from the project file via:

  <ItemGroup>
    <FrameworkReference Update="Microsoft.NETCore.App" RuntimeFrameworkVersion="8.0.0-dev" />
    <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="8.0.0-dev" />
  </ItemGroup>

The measurements show the following results:

TodosApi main this PR
Size on disk (Mb) 49,99 36,25

These numbers do not match what you posted in: #89527 (comment) but I only have a MacBookPro M1 at hand, so am not able to verify the impact of this change on win-x64. Nevertheless, presented measurements show the expected reduction in size.

I also double-checked the mstat files. confirming the fix:

main branch:
main-branch

this PR:
this-PR

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

@MichalStrehovsky MichalStrehovsky merged commit 8c96dd2 into dotnet:main Jul 31, 2023
195 of 213 checks passed
@ivanpovazan ivanpovazan deleted the fix-refactor-linq-expr-switches branch July 31, 2023 07:37
@ghost ghost locked as resolved and limited conversation to collaborators Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NativeAOT] System.Linq.Expressions size regression
3 participants