Skip to content

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

@simonrozsival

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions