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

Use precompiled DEX files to speed builds #9534

Open
jpobst opened this issue Nov 20, 2024 · 0 comments
Open

Use precompiled DEX files to speed builds #9534

jpobst opened this issue Nov 20, 2024 · 0 comments
Labels
Area: App+Library Build Issues when building Library projects or Application projects. Area: Performance Issues with performance.
Milestone

Comments

@jpobst
Copy link
Contributor

jpobst commented Nov 20, 2024

Our _CompileToDalvik task is currently the most expensive part of a user application build.

For example, for the following sample:

dotnet new android
dotnet add package Xamarin.AndroidX.Activity --version 1.9.3.1

This passes 34 dependency .jars to the _CompileToDalvik task, which takes ~11.5s to execute on a DevBox.

D8 provides the ability to compile a library individually ahead of time. When the "final" compilation is done it only needs to copy over the DEX code rather than compile it.

android-toolchain\jdk-17\bin\java.exe
  -Xmx1G
  -classpath "C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.7\tools\r8.jar"
  com.android.tools.r8.D8
  --debug
  --min-api 24
  --output "mono.android.24.dex"
  "C:\Program Files\dotnet\packs\Microsoft.Android.Ref.35\35.0.7\ref\net9.0\mono.android.jar"

Precompiling the 34 dependency .jars and using them reduces the "final" _CompileToDalvik invocation to ~5.2s. 🎉

Wrinkles

The biggest wrinkle to this is that the output is different based on the --min-sdk that is passed in (particularly around desugaring), so we can't have a single precompiled DEX file. In theory we would need one per possible min-sdk, unless we can prove that we only need ones for API-21 and API-24. This makes it harder to ship precompiled binaries if we need to ship ~14 API levels.

Ideally, we could simply perform this compilation on first use and cache it, however it takes an extensive amount of time to precompile each .jar file. It takes about ~88s to precompile the 34 dependency .jars used in the test above. This is a considerably longer "first compile" than not using caching at all.

@jpobst jpobst added Area: App+Library Build Issues when building Library projects or Application projects. Area: Performance Issues with performance. labels Nov 20, 2024
@jpobst jpobst added this to the .NET 10 milestone Nov 20, 2024
@dotnet-policy-service dotnet-policy-service bot added the needs-triage Issues that need to be assigned. label Nov 20, 2024
@jpobst jpobst removed the needs-triage Issues that need to be assigned. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. Area: Performance Issues with performance.
Projects
None yet
Development

No branches or pull requests

1 participant