-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize FieldAccessor
#335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to have some benchmark for this change.
@@ -56,8 +56,8 @@ private static FieldAccessor CreateFieldAccessor(Type accessorType, FieldInfo fi | |||
accessorType.CachedMakeGenericType(field.ValueType), | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
FieldIndex
field instead ofFieldInfo.MappingInfo.Offset
expression will save one pointer dereference.