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

[Mono] Fix all the issues related to enabling WasmStripILAfterAOT #90436

Merged
merged 79 commits into from
Nov 13, 2023

Conversation

fanyang-mono
Copy link
Member

@fanyang-mono fanyang-mono commented Aug 11, 2023

This PR enables IL trim by default for WASM apps, by solving the following major problems:

  • There are various opcode which was translated into a function call. I modified the call goto logic to check if there is an AOT'ed version of the callee method. If there is, invoke that. If there isn't, interp compile the callee method.
  • Move the logic of checking if a method is supported a JIT/AOT call from interpreter callback to mini-runtime.c. Because the callback was initialized with the desired logic only when mono_use_interpreter is set to true. See the following code
    #ifndef DISABLE_INTERPRETER
    if (mono_use_interpreter)
    mono_ee_interp_init (mono_interp_opts_string);
    #endif

    However, in driver.c, mono_use_interpreter was not set to true during AOT compile time, even though interp was passed in as an AOT option. It would be set to true during AOT runtime. Alter this behavior is probably not desirable. Thus, I choose to move the checking logic to mini-runtime.c
  • Set the trimmed assemblies with the same timestamp as the original assemblies. So that it won't trigger unwanted rebuild or re-AOT
  • Added implementation of g_fopen to properly handle unicode string on windows.
  • Interpreter can't do JIT call for methods which require synchronization. Remove those methods from trimmable method list.
  • Disabled tailcall optimization when calling trimmed methods.
  • Do jitcall when encountering virtual tailcalls.
  • Change of ILStrip task:
    • The trimmed assemblies were saved in a new folder with the same name as the original assembly.
    • Created an output variable UpdatedAssemblies with the updated path of assemblies. The trimmed assemblies are updated with their new path.
    • Updated the WASM build toolchain to replace the content of _WasmAssembliesInternal with UpdatedAssemblies
  • Added the input parameter WasmRuntimeConfigFilePath for WasmAppBuilderBaseTask. Got rid of the logic to calculate the path of runtimeconfig.json file. Use the value of WasmRuntimeConfigFilePath instead. (Fixes [wasm] The way of getting the path of runtimeconfig.json file is not always reliable #93692)
  • Found two issues related to wasm build process. @radical fixed them.
  • Blazor app is able to packages the trimmed assemblies, when WasmStripILAfterAOT is enabled.
  • Added tests for wasm template app and blazor template app

Library size change for top 3 largest libraries:

  • System.Private.CoreLib.dll.br: 452k -> 316K
  • System.Text.Json.dll.br: 109k -> 81k
  • Microsoft.AspNetCore.Components.dll.br: 69k -> 54k

@ghost ghost assigned fanyang-mono Aug 11, 2023
@fanyang-mono fanyang-mono changed the title [Mono] Enable IL trim for WASM apps by default [Mono][WIP] Enable IL trim for WASM apps by default Aug 11, 2023
@SamMonoRT
Copy link
Member

cc @lewing @kg

@SamMonoRT
Copy link
Member

As discussed, merge this only after RC1 has forked and discussions with @lewing

…ld call an AOT'ed version of it before trying to interp compile it
@fanyang-mono fanyang-mono marked this pull request as ready for review September 7, 2023 13:21
@fanyang-mono fanyang-mono changed the title [Mono][WIP] Enable IL trim for WASM apps by default [Mono] Enable IL trim for WASM apps by default Sep 7, 2023
@radical
Copy link
Member

radical commented Nov 9, 2023

I would suggest splitting this PR into:

  1. the mono/mono, and src/libraries changes
  2. RuntimeConfigJsonPath change, and the bit in Browser.targets
  3. Rest of the changes

@fanyang-mono
Copy link
Member Author

/azp run runtime-wasm

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member

radical commented Nov 10, 2023

As discussed offline, I have pushed the following changes:

  • reverted the rebuild-if-the-property-changes

Also:

  • the tests were explicitly disabling webcil, fixed that to work with webcil, though the tests compare the file size which is not useful for webcil case. In a future PR we should check for stripping in some other way
  • Added another case for testing the non-default value also

@radical radical dismissed their stale review November 10, 2023 05:40

new changes pushed

@radical
Copy link
Member

radical commented Nov 10, 2023

/azp run runtime-wasm

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@radical radical left a comment

Choose a reason for hiding this comment

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

Thank you for your patience! LGTM 👍

@fanyang-mono
Copy link
Member Author

/azp run runtime-wasm

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@fanyang-mono fanyang-mono changed the title [Mono] Enable IL strip for WASM apps by default [Mono] Fix all the issues related to enabling WasmStripILAfterAOT Nov 13, 2023
@fanyang-mono
Copy link
Member Author

/azp run runtime-wasm

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@fanyang-mono
Copy link
Member Author

According too Build Analysis, all test failures are known.

@fanyang-mono fanyang-mono merged commit 085ddb7 into dotnet:main Nov 13, 2023
193 of 199 checks passed
jonpryor pushed a commit to dotnet/android that referenced this pull request Dec 4, 2023
Changes: dotnet/installer@e1fd7d9...42ace91

	% git diff --shortstat e1fd7d9649...42ace91ba7
	 182 files changed, 8428 insertions(+), 2413 deletions(-)

Changes: dotnet/runtime@287c10d...a26802a

	% git diff --shortstat 287c10d253...a26802aa57
	 10852 files changed, 266698 insertions(+), 198289 deletions(-)

Changes: dotnet/emsdk@1999c8c...74e4868

	% git diff --shortstat 1999c8c8ab...74e4868be8
	 39 files changed, 616 insertions(+), 260 deletions(-)

Changes: dotnet/cecil@a112f15...45dd3a7

  * dotnet/cecil@45dd3a7: [main] Update dependencies from dotnet/source-build-reference-packages (dotnet/cecil#116)
  * dotnet/cecil@0b78015: Update dependencies from https://github.com/dotnet/arcade build 20231008.1 (dotnet/cecil#115)
  * dotnet/cecil@64a8874: [main] Update dependencies from dotnet/source-build-reference-packages (dotnet/cecil#114)
  * dotnet/cecil@13d6536: [main] Update dependencies from dotnet/source-build-reference-packages (dotnet/cecil#113)
  * dotnet/cecil@89be445: [main] Update dependencies from dotnet/source-build-reference-packages (dotnet/cecil#112)
  * dotnet/cecil@84f4527: Update dependencies from https://github.com/dotnet/arcade build 20230913.1 (dotnet/cecil#111)

Changes: dotnet/android-tools@08a6990...21de3d7

  * dotnet/android-tools@21de3d7: [build] update $(MSBuildPackageReferenceVersion) to 17.6.3 (dotnet/android-tools#221)

Updates:

  * Microsoft.Dotnet.Sdk.Internal: from 8.0.100-rc.2.23468.1 to 9.0.100-alpha.1.23603.1
  * Microsoft.NETCore.App.Ref: from 8.0.0-rc.2.23466.4 to 9.0.0-alpha.1.23577.7
  * Microsoft.NET.Workload.Emscripten.Current.Manifest-*.Transport: from 8.0.0-rc.2.23463.1 to 9.0.0-alpha.1.23572.3
  * Microsoft.DotNet.Cecil: from 0.11.4-alpha.23461.1 to 0.11.4-alpha.23509.2

~~ Changes to the build ~~

`$(DotNetTargetFrameworkVersion)` is `9.0`, making assemblies like
`Mono.Android.dll` target .NET 9.0, as well as `$(TargetFramework)`
in project templates, etc.

`$(DotNetStableTargetFramework)` is `8.0`, making various bootstrap
tooling, command-line tools, and unit tests target .NET 8.0.

.NET 9 has a new `.binlog` format, requiring
`MSBuild.StructuredLogger` 2.2.100.

`System.CodeDom` now targets 8.0.0, as we moved to 17.8 MSBuild
assemblies from `xamarin-android-tools`.

Add the `dotnet9` and `dotnet9-transport` feeds. The
`dotnet9-transport` feed is used for non-customer-facing packages
like `Microsoft.NET.ILLink`.

`build-linux.yaml` was initially failing to restore `net8.0`
projects because of the order it installed a .NET SDK. It was only
working for `net7.0` projects, because a .NET 7 SDK was
preinstalled on the build machines.

Update `TestSlicerToolVersion` and `dotnet-test-slicer` to
`0.1.0-alpha7`, previously it was failing to discover tests in a
`net8.0` project.

Provision Mono workload manifests for: `net6`, `net7`, `net8`, and
`current` (`net9`).  Call `Utilities.DeleteDirectory()` on these
directories to be sure we are in a clean state.

dotnet/android-tools@21de3d7 is needed to fix various
NU1605 warnings:

	error NU1605: Warning As Error: Detected package downgrade: Microsoft.Build.Framework from 17.5.0 to 17.3.2. Reference the package directly from the project to select a different version.
	error NU1605:  MSBuildDeviceIntegration -> MSBuild.StructuredLogger 2.2.100 -> doh (>= 17.5.0)
	error NU1605:  MSBuildDeviceIntegration -> Microsoft.Build.Framework (>= 17.3.2)

Update workload aliases to include `Microsoft.Android.Sdk.net9` and
`Microsoft.Android.Sdk.net8`.

Remove the .NET 7 Android workload from .NET 9.
Import `Eol.targets` for .NET 6/7 projects.

Update various parameterized tests to target `net8.0` and `net9.0`
appropriately while dropping `net7.0` support.

An initial update to the AOT profile for .NET 9.

Updated `*.apkdesc` files: there were some minor `.apk`
size changes.


~~ `$(AllowSelfContainedWithoutRuntimeIdentifier)` ~~

Context: dotnet/sdk@d21e6bf
Context: d12da3a

@rolfbjarne introduced an "escape hatch" in the .NET 9 SDK for emitting
a build warning for a case that doesn't make sense on mobile.
All mobile apps are self-contained, and we define RIDs by default, so
the error is not needed.

We can also stop setting `$(PublishSelfContained)` to `false`, as
`$(AllowSelfContainedWithoutRuntimeIdentifier)` is sufficient in .NET 9.


~~ Changes to `<ILStrip/>` ~~

Context: dotnet/runtime#90436

  * `$(IntermediateOutputPath)` is now required.

  * `[Output] TrimmedAssemblies` renamed to `UpdatedAssemblies`.

  * Output items shape changed, so now use
    `%(UntrimmedAssemblyFilePath)` and we can `<Copy/>` based on
    `%(ILStripped)`.

The new code is better, so generally these changes seem *good*.


~~ Refactoring ~~

Rename `$(AndroidNet7Version)` to `$(AndroidNetPreviousVersion)` to make
this property more generic for future releases.

Use `@NET_PREVIOUS_VERSION@` as a replacement instead of `@NET7_VERSION@`.


~~ TODO ~~

  * #8548

    The `MicrosoftIntune` test is failing because they have a check for
    == `8.0` that needs to be updated to be >= `8.0`.  This test is
    running on our `release/8.0.1xx` branch, but we can hopefully
    re-enable in main after their next release.

  * A specific case of `dotnet publish -f net8.0-android -r android-arm`
    is failing with:

        error NETSDK1185: The Runtime Pack for FrameworkReference 'Microsoft.Android.Runtime.34.android-arm' was not available. This may be because DisableTransitiveFrameworkReferenceDownloads was set to true.

    This is related to `$(AllowSelfContainedWithoutRuntimeIdentifier)`,
    but I will address in a future PR.  This will likely require .NET 8
    Android workload changes.
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
9 participants