The problem
Currently bindings generator makes the following code for a single property:
public Reactive.IState<string> sText {
set {
value.ValueChangedEvent += x => obj.Text = x;
}
}
Take a close look at the code: each call to this property allocates a delegate and a lambda instance which is very expensive.
The solution
Change the ValueChangedEvent signature so that we pass an instance directly via the event, instead of capturing it into the lambda in-place:
interface IState {
...
void AddCallback(object instance, Action<object, T> callback);
void RemoveCallback(object instance, Action<object, T> callback);
}
public Reactive.IState<string> sText {
set {
value.AddCallback(obj, static (x, val) => ((Label)x).Text = val);
}
}
In this case both the lambda and the delegate are allocated only once and then cached by the compiler. However this method adds a castclass instruction, but the tradeoff is negligible as GC pressure is a more significant problem.
The problem
Currently bindings generator makes the following code for a single property:
Take a close look at the code: each call to this property allocates a delegate and a lambda instance which is very expensive.
The solution
Change the
ValueChangedEventsignature so that we pass an instance directly via the event, instead of capturing it into the lambda in-place:In this case both the lambda and the delegate are allocated only once and then cached by the compiler. However this method adds a
castclassinstruction, but the tradeoff is negligible as GC pressure is a more significant problem.