-
Notifications
You must be signed in to change notification settings - Fork 576
[NativeAOT] Trim unused typemap Java code in Release #12228
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,9 @@ public class GenerateNativeAotProguardConfiguration : AndroidTask | |
| public string OutputFile { get; set; } = ""; | ||
|
|
||
| // When false, the ILC DGML is not consulted (it may not have been generated at all) and a | ||
| // -keep rule is emitted for every Java Callable Wrapper in the ACW map, so R8 keeps them all | ||
| // instead of shrinking the unused ones. This trades a small amount of dex size for skipping the | ||
| // very large DGML files and the DGML parsing/scan, which dominate NativeAOT build time. | ||
| // -keep rule is emitted for every Java type in the ACW map, so R8 keeps them all instead of | ||
| // shrinking the unused ones. Large binding closures can add several MB of compressed DEX, but | ||
| // this avoids generating and processing the very large ILC dependency graph. | ||
| public bool TrimJavaCallableWrappers { get; set; } = true; | ||
|
|
||
| public override bool RunTask () | ||
|
|
@@ -56,7 +56,7 @@ public override bool RunTask () | |
| retainedTypeKeys = LoadRetainedTypeKeysFromDgml (); | ||
| } | ||
|
|
||
| // A null retainedTypeKeys means "keep every ACW" (Java trimming disabled). | ||
| // A null retainedTypeKeys means "keep every Java type in the ACW map" (Java trimming disabled). | ||
| var javaTypes = LoadJavaTypesFromAcwMap (retainedTypeKeys); | ||
|
|
||
| using var writer = new StringWriter (); | ||
|
|
@@ -69,7 +69,7 @@ public override bool RunTask () | |
| if (TrimJavaCallableWrappers) { | ||
| Log.LogMessage (MessageImportance.Low, "Generated {0} NativeAOT trimmable typemap ProGuard rules from {1} DGML file(s).", javaTypes.Count, NativeAotDgmlFiles.Length); | ||
| } else { | ||
| Log.LogMessage (MessageImportance.Low, "Generated {0} NativeAOT ProGuard rules keeping all ACWs (Java Callable Wrapper trimming is disabled).", javaTypes.Count); | ||
| Log.LogMessage (MessageImportance.Low, "Generated {0} NativeAOT ProGuard rules keeping every Java type in the ACW map (Java trimming is disabled).", javaTypes.Count); | ||
| } | ||
| return !Log.HasLoggedErrors; | ||
| } | ||
|
|
@@ -101,7 +101,18 @@ HashSet<string> LoadRetainedTypeKeysFromDgml () | |
| XmlResolver = null, | ||
| }); | ||
|
|
||
| bool readingNodes = false; | ||
| while (reader.Read ()) { | ||
| if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "Nodes") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 💡 JNI interop / Robustness — Scoping the scan to the |
||
| readingNodes = true; | ||
| continue; | ||
| } | ||
| if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "Nodes") { | ||
| break; | ||
| } | ||
| if (!readingNodes) { | ||
| continue; | ||
| } | ||
| if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "Node") { | ||
| continue; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 💡 MSBuild targets — These explicit
--scandgmllog/--dgmllogargs are only added whenIlcGenerateDgmlFile != 'true'. When a user does setIlcGenerateDgmlFile=true, generation falls back to ILC's own DGML output, but_CollectTrimmableNativeAotDgmlFilesonly looks for$(TargetName).scan.dgml.xml/$(TargetName).codegen.dgml.xml. Are you sure ILC'sIlcGenerateDgmlFilepath emits files with those exact names/locations? If it uses a different name (e.g.$(TargetName).dgml.xml), the collect step could come up empty and tripXA4319— most likely in an unoptimized build where only the codegen graph exists. Worth a quick confirmation since that path is less exercised than the default.