-
Notifications
You must be signed in to change notification settings - Fork 567
Open
Labels
Description
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 inImplementor. 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
- Epic: [TrimmableTypeMap] TypeMap assembly + JCW Java source generators #10799
- Initial prototype removed in PR [TrimmableTypeMap] Add TypeMap proxy groundwork with CreateInstance #10808
Reactions are currently unavailable