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] System.Linq.Expressions size regression #89527

Closed
eerhardt opened this issue Jul 26, 2023 · 6 comments · Fixed by #89638
Closed

[NativeAOT] System.Linq.Expressions size regression #89527

eerhardt opened this issue Jul 26, 2023 · 6 comments · Fixed by #89638
Assignees
Labels
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Jul 26, 2023

Description

The "Stage2" / "TodosAPI" ASP.NET benchmark app's NativeAOT size has regressed in recent builds.

image

As you can see, the size increased from 31 MB to 41 MB.

Looking at the mstat diffs, I see most of the size increase coming from System.Linq.Expressions. This leads me to believe this was regressed by #89308.

Configuration

All

Regression?

Yes

Data

The before and after mstat files can be found in:
MStatFiles.zip

Analysis

Diffing the attached mstat files in sizoscope shows:

image

cc @MichalStrehovsky @ivanpovazan

@eerhardt eerhardt added the tenet-performance Performance related issue label Jul 26, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 26, 2023
@ghost
Copy link

ghost commented Jul 26, 2023

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

Issue Details

Description

The "Stage2" / "TodosAPI" ASP.NET benchmark app's NativeAOT size has regressed in recent builds.

image

As you can see, the size increased from 31 MB to 41 MB.

Looking at the mstat diffs, I see most of the size increase coming from System.Linq.Expressions. This leds me to believe this was regressed by #89308.

Configuration

All

Regression?

Yes

Data

The before and after mstat files can be found in:
MStatFiles.zip

Analysis

Diffing the attached mstat files in sizoscope shows:

image

cc @MichalStrehovsky @ivanpovazan

Author: eerhardt
Assignees: -
Labels:

tenet-performance, area-NativeAOT-coreclr

Milestone: -

@MichalStrehovsky
Copy link
Member

Looks like we no longer trim the Ref.Emit backend or the CanCreateArbitraryDelegates code path. It likely is from #89308. I think we'll need to undo removal of the other two switches and only leave the CanEmitObjectArrayDelegate change. (The two switches can/should stay as --feature).

@ivanpovazan ivanpovazan self-assigned this Jul 27, 2023
@ivanpovazan
Copy link
Member

That is a bit unexpected as both:

public static bool CanCompileToIL => RuntimeFeature.IsDynamicCodeSupported;

and
private static bool CanCreateArbitraryDelegates => RuntimeFeature.IsDynamicCodeSupported;

are guarded by IsDynamicCodeSupported which should be set to false in NativeAOT scenarios:
<DynamicCodeSupport Condition="'$(DynamicCodeSupport)' == ''">false</DynamicCodeSupport>

I will try to repro and revert if needed.

@MichalStrehovsky
Copy link
Member

Dead branch removal rules are undocumented and unreliable. One needs to basically always re-test if this is shuffled. I think the problem here is that if we're in a situation where there is if (Something()) { ... } and Something() becomes obviously constant only after inspecting that method body, the branch will not be removed by NativeAOT. It will be removed by ILLinker if it runs before NativeAOT because ILLinker does propagate across methods but we don't run with ILLinker outside AppleMobile.

@eerhardt
Copy link
Member Author

I was able to verify the regression happened between 5b4bbda...d389ab9.

To repro:

dotnet publish the app at https://github.com/aspnet/Benchmarks/tree/main/src/BenchmarksApps/TodosApi. You can use different official builds of the runtime by changing the .csproj:

<ItemGroup>
  <FrameworkReference Update="Microsoft.NETCore.App"
                      RuntimeFrameworkVersion="8.0.0-rc.1.23374.1" />
  <PackageReference Include="Microsoft.Dotnet.ILCompiler"
                    Version="8.0.0-rc.1.23374.1" />
</ItemGroup>

With that version, the size on my win-x64 machine is 27.4 MB. Note that version is from commit 5b4bbda.

<ItemGroup>
  <FrameworkReference Update="Microsoft.NETCore.App"
                      RuntimeFrameworkVersion="8.0.0-rc.1.23375.8" />
  <PackageReference Include="Microsoft.Dotnet.ILCompiler"
                    Version="8.0.0-rc.1.23375.8" />
</ItemGroup>

With that version, the size on my win-x64 machine is 34.4 MB. Note that version is from commit d389ab9.

@ivanpovazan
Copy link
Member

I have verified that the regression is introduced with: #89308
I will try to get a fix for this soon - targeting rc1.
If it is urgent to get steady perf reports, I can revert the change and apply a proper fix afterwards.

@eerhardt eerhardt added this to the 8.0.0 milestone Jul 27, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 27, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 28, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 31, 2023
@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.
Labels
Projects
None yet
3 participants