Skip to content

[MAUI] Measure only APK in Android SOD jobs - #5265

Merged
LoopedBard3 merged 1 commit into
mainfrom
dev/simonrozsival/fix-maui-android-apk-size-sod
Jul 27, 2026
Merged

LoopedBard3 merged 1 commit into
mainfrom
dev/simonrozsival/fix-maui-android-apk-size-sod

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • stage only the signed APK and versions.json for MAUI Android SizeOnDisk work items
  • prevent R8 mapping files, binlogs, and resource-designer assemblies from being reported as APK size
  • preserve the existing extracted-APK measurement and leave startup/build-time payloads unchanged

Background

Related: dotnet/android#12184

@matouskozak The NativeAOT MAUI sample-content chart jumped from roughly 27 MB to 53 MB after dotnet/android enabled the trimmable typemap by default. The trimmable path also enables R8, which publishes a large mapping.txt beside the APK.

The SOD work item recursively copied the complete correlation output into pub, and SizeOnDisk recursively measured that directory. Running the unmodified scenario against a reproduced payload reported 52,797,806 bytes, comprising:

  • APK: 21,561,293 bytes
  • mapping.txt: 28,318,349 bytes
  • publish and restore binlogs: 2,056,465 bytes
  • resource designer: 861,696 bytes
  • versions.json: 3 bytes

The actual trimmable APK is smaller than the previous managed-typemap APK; the regression is in measurement composition.

This change stages only the APK and versions.json for the two SOD work items. test.py consumes and removes versions.json in lab runs before invoking SizeOnDisk.

Validation

  • APK Size: 21,561,293 bytes, one counted APK
  • Extracted Size: 53,077,875 bytes, 1,435 APK member files
  • no mapping files, binlogs, or loose build outputs are included in either result

Stage only the signed APK and versions metadata for Android SizeOnDisk work items so mapping files, binlogs, and other publish sidecars are not reported as APK size.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a301fa68-0e6c-4280-b2f2-bc3d4c9ae3de
Copilot AI review requested due to automatic review settings July 23, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes MAUI Android SizeOnDisk (SOD) measurements in Helix by staging only the signed APK (plus versions.json) into the pub directory, avoiding accidental inclusion of extra publish artifacts (e.g., R8 mapping.txt, binlogs, resource-designer assemblies) in the “APK size” metric.

Changes:

  • Update Android SOD work item pre-commands to copy only *.apk and versions.json into pub instead of recursively copying the entire correlation output.
  • Keep the extracted-APK measurement behavior by still expanding the APK contents into pub for the “Extracted Size” work item.
Show a summary per file
File Description
eng/performance/maui_scenarios_android.proj Adjusts Android SOD Helix work items to stage only the intended measurement inputs (APK + versions metadata) into pub to prevent inflated size reporting.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@matouskozak matouskozak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@LoopedBard3
LoopedBard3 merged commit 100ccae into main Jul 27, 2026
76 checks passed
@LoopedBard3
LoopedBard3 deleted the dev/simonrozsival/fix-maui-android-apk-size-sod branch July 27, 2026 18:14
simonrozsival added a commit to dotnet/android that referenced this pull request Aug 25, 2026
## Summary

- enable DGML-filtered R8 keep rules by default for optimized NativeAOT trimmable-typemap builds
- emit only the scan graph in optimized builds or the codegen graph in unoptimized explicit opt-ins, instead of always producing both
- serialize graph-producing multi-RID NativeAOT builds to avoid system file-table exhaustion
- stop DGML parsing after the `Nodes` section and add runtime-host/incremental coverage

## Context

Related to #12184.

The performance-chart discontinuity is separately addressed by dotnet/performance#5265, but the APK investigation found real Java-side over-retention. With Java trimming disabled, R8 keeps all 13,007 Java names from `acw-map.txt`, even though ILC retains only 1,132 typemap records for this app.

For `dotnet new maui --sample-content`, `android-arm64`, Release NativeAOT:

| Metric | Keep all Java types | Filtered keep rules | Delta |
| --- | ---: | ---: | ---: |
| Signed APK | 21,876,685 B | 18,931,603 B | -2,945,082 B |
| Raw DEX | 13,626,844 B | 5,171,592 B | -8,455,252 B |
| Java keep rules | 13,007 | 1,154 | -11,853 |
| NativeAOT shared library | 32,019,032 B | 32,019,032 B | 0 B |

The removed Java closure includes all 2,253 Tink classes, AndroidX Security Crypto, and thousands of unused AndroidX/Kotlin/Material classes.

## DGML and build impact

The previous opt-in used `IlcGenerateDgmlFile=true`, which emitted both graphs:

- scan DGML: 545,822,343 B
- codegen DGML: 426,448,469 B
- total: 972,270,812 B

This change requests only the graph needed by the current compilation mode. A normal optimized build now writes only the 545,822,343-byte scan graph. Explicit `IlcGenerateDgmlFile=true` still produces both diagnostic graphs.

Two warm-cache clean runs per mode on macOS arm64 measured:

| Mode | Mean wall time | Mean peak RSS | DGML |
| --- | ---: | ---: | ---: |
| Java trimming off | 137.03 s | 2.29 GB | 0 B |
| Previous full-DGML opt-in | 136.53 s | 3.15 GB | 972,270,812 B |
| This change | 128.07 s | 2.65 GB | 545,822,343 B |

The wall-clock impact is near-neutral because ILC/report generation is offset by R8 processing a much smaller retained Java graph. The remaining tradeoff is approximately 546 MB of intermediate disk per RID and roughly 0.36 GB additional peak RSS versus keeping all Java types.

No-change publishes remain incremental (about 5-7 seconds): ILC and ProGuard generation skip, and the graph/config/APK timestamps remain unchanged. Source changes rerun ILC, while unchanged keep rules prevent unnecessary javac/R8/APK work.

## Correctness

- Release defaults Java trimming on; Debug remains off because its 790 MB codegen graph produced no Java-size benefit.
- A true -> false -> source change -> true sequence with a new retained Java peer regenerated the graph and retained the new peer.
- Multi-RID graph generation is serialized after parallel ILC graph writers reproduced system file-table exhaustion.
- The sample-content APK installed and launched on an API 36 arm64 emulator and survived 100 Monkey events without a Java class/method failure.

## Tests

```text
./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll \
  --filter FullyQualifiedName~Execute_GenerateNativeAotProguardConfiguration

./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll \
  --filter FullyQualifiedName~Build_WithTrimmableTypeMap_IncrementalBuild \
  -- NUnit.NumberOfTestWorkers=1

./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll \
  --filter FullyQualifiedName~Build_WithTrimmableTypeMap_KeepsNativeAotRuntimeHostAcws \
  -- NUnit.NumberOfTestWorkers=1
```


## Why not use `IlcGenerateDgmlFile`?

The upstream `IlcGenerateDgmlFile=true` switch expands to both `--dgmllog` and `--scandgmllog`. For this sample that writes 426,448,469 bytes of codegen DGML plus 545,822,343 bytes of scan DGML (972,270,812 bytes per RID).

The Android keep-rule task consumes only the scan graph in optimized builds. In unoptimized builds the scanner does not run, so it consumes only the codegen graph. This change passes the required argument directly to avoid generating the other several-hundred-megabyte file.

Explicitly setting `IlcGenerateDgmlFile=true` continues to request and preserve both graphs for full ILC diagnostics. A cleaner long-term upstream API would expose independent scan/codegen DGML properties.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants