Skip to content

[typemap] Trim unused listener implementors from existing bindings - #12404

Draft
simonrozsival wants to merge 2 commits into
mainfrom
dev/simonrozsival/trimmable-managed-created-peers
Draft

[typemap] Trim unused listener implementors from existing bindings#12404
simonrozsival wants to merge 2 commits into
mainfrom
dev/simonrozsival/trimmable-managed-created-peers

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 17, 2026

Copy link
Copy Markdown
Member

Summary

Binding-generated listener implementors in non-framework assemblies are currently emitted as unconditional TypeMap entries. This keeps the managed implementor, JCW, ACW map entry, ProGuard rule, and DEX class even when the corresponding C# event is never used.

This change recognizes the binding generator's existing implementor shape:

  • JNI name starts with mono/
  • sealed ACW implementing a Java interface
  • static bool __IsEmpty(TImplementor) helper used by generated event removal

Matching implementors now use conditional TypeMap entries and follow managed reachability. Explicit manifest/component roots still take precedence, and ordinary user ACWs remain conservative and unconditional.

Compatibility

This works with existing compiled binding assemblies. It adds no attributes, public API, or generator metadata and does not require bindings to be regenerated. Detection uses the generated metadata shape rather than only an Implementor type-name suffix.

Follow-up to #10911. This also adapts the reachability idea discussed around #12272 to the trimmable typemap.

Validation

  • Microsoft.Android.Sdk.TrimmableTypeMap.Tests: 802 passed
  • local SDK product build completed
  • tested with a binding generated by unmodified main, containing no new metadata:
    • unused event: implementor removed from linked IL, post-link Java, ACW map, ProGuard rules, and DEX
    • subscribed event: implementor retained in every corresponding output
  • trimming the single validation implementor reduced the signed APK by 4 KiB

Mark generated listener implementors as managed-created and model their Java peers conditionally so unused implementors can be removed by trimming.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 568c6ce4-aef4-44cd-bd52-d5950a5da923
@simonrozsival simonrozsival changed the title [typemap] Trim managed-created Java peers [TrimmableTypeMap] Trim managed-created Java peers Aug 17, 2026
Replace the explicit managed-created metadata contract with backward-compatible detection of the existing binding-generator implementor shape.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 568c6ce4-aef4-44cd-bd52-d5950a5da923
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Trim managed-created Java peers [typemap] Trim generated binding listener implementors Aug 17, 2026
@simonrozsival simonrozsival changed the title [typemap] Trim generated binding listener implementors [typemap] Trim unused listener implementors from existing bindings Aug 17, 2026
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.

1 participant