Generalize trampoline code to allow reuse and reduce code size
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
### Steps to Reproduce
1. Build xamarin-macios
2. Open generated file `Trampolines.g.cs`
### Expected Behavior
A single instance of trampolines to invoke a `NSObject` / `INative`
### Actual Behavior
Each case is specialized to it's own type, e.g.
```csharp
[Preserve (Conditional=true)]
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
unsafe void Invoke (global::AVFoundation.AVAsynchronousCIImageFilteringRequest obj)
{
invoker (blockPtr, obj == null ? IntPtr.Zero : obj.Handle);
}
```
Which lead to code duplication, the linker will remove unused ones, but it still won't go down to 1 (and the linker can be disable, e.g. interpreter).
E.g. There are 171 instances (for iOS on xcode11 branch) of
```csharp
invoker (blockPtr, obj == null ? IntPtr.Zero : obj.Handle);
```
That affects app size and build time (more to AOT).
There are more candidates for optimization - but that one seems easy and quite frequent.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.