Skip to content

[TrimmableTypeMap] Explore trimming optimization for Implementor and EventDispatcher types #10911

Closed

Description

@simonrozsival

Part of #10799

Summary

Implementor (e.g., IOnClickListenerImplementor) and EventDispatcher types are generated by the binding generator and are only instantiated from .NET code (e.g., when a C# event is subscribed). They are never instantiated from Java directly.

Currently, the TrimmableTypeMap treats them as unconditional ACW types (always preserved), matching the legacy type map behavior. However, these types are candidates for trimming — if the app never subscribes to the corresponding C# event, the Implementor/EventDispatcher and its JCW could be removed.

Proposed optimization

Use the 3-arg TypeMap attribute (trimmable) instead of the 2-arg (unconditional) for these types, allowing the trimmer to remove them when unused.

Considerations

  • Detection: These types have no special attributes. The binding generator gives Implementors a JNI name starting with mono/ and a managed name ending in Implementor. EventDispatchers follow a similar pattern. A heuristic combining JNI prefix + name suffix was prototyped in PR [TrimmableTypeMap] Add TypeMap proxy groundwork with CreateInstance #10808 but removed to avoid unintentional regressions.
  • Correctness: Need to verify that trimming these types doesn't break runtime behavior (e.g., if event subscription is done via reflection or late binding).
  • Test coverage: Need integration tests that verify trimmed apps still work correctly when events are and aren't used.
  • Alternative: The Java.Interop binding generator could be updated to emit a dedicated attribute or metadata flag on these types, making detection reliable without heuristics.

References

Activity

  1. added
    needs-triage
    on Mar 10, 2026
  2. simonrozsival commented on May 25, 2026

    @simonrozsival
    MemberAuthor

    Closing as addressed by #11345.

    That PR removed the ForceUnconditionalEntries workaround and restored conditional/trimmable TypeMap entries for framework ACW helper types. The current model coverage also asserts framework ACWs are conditional rather than unconditionally rooting their proxy types, which covers the core Implementor/EventDispatcher trimming optimization tracked here.

    If we want additional event-specific integration coverage, that should be tracked separately rather than keeping this optimization issue open.

  3. locked and limited conversation to collaborators on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triagetrimmable-type-map

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions