Optimize FieldAccessor - #335
Conversation
snaumenko-st
left a comment
There was a problem hiding this comment.
It'd be great to have some benchmark for this change.
| BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, | ||
| null, Array.Empty<object>(), null); | ||
| accessor.Field = field; | ||
| accessor.SetFieldInfo(field); |
There was a problem hiding this comment.
Thinking out loud: maybe we can convert all these accessors to structs and get rid of virtual call dispatching as well? E.g. make them generic arguments of FieldAccessor
Could it be possible?
And maybe we can replace SetFieldInfo with single ctor argument?
There was a problem hiding this comment.
This operation .SetFieldInfo() invoked only once, during Domain building
Little profit of optimizing it.
And I don't see easy way to use Accesor.GetValue()/SetValue() without virtual functions.
It would be to emulate vtbl by some other means
There was a problem hiding this comment.
I mean not only this operation is worth optimizing. But others as well. These accessors seem to be good candidates for compiler optimizations with devirtualizing. There is not much of shared code and actually there is little sense to use inheritance.
There was a problem hiding this comment.
I had an idea to inherit *Accessor from FieldInfo
because they are always together and mutually referenced
that will save yet one pointer dereference during access
This class is critical for the performance.
Most of them are value-type accessors (
DefaultFieldAccessor<>).Using
FieldIndexfield instead ofFieldInfo.MappingInfo.Offsetexpression will save one pointer dereference.