简体   繁体   English

如何加快FieldInfo.GetValue()的调用?

[英]How to speed up FieldInfo.GetValue() calls?

I'm using FieldInfo.GetValue() calls intensively in custom serializer. 我在自定义序列化程序中大量使用FieldInfo.GetValue()调用。 This function is really slow. 这个功能真的很慢。

1) Is there a portable way to speed it up? 1)是否有一种便携式方法来加快速度? I don't need any checks done by FieldInfo.GetValue() implementation, I just need to get that value quickly. 我不需要FieldInfo.GetValue()实现进行任何检查,只需要快速获取该值即可。

Now about a non-portable way. 现在介绍一种非便携式方式。 I use Mono. 我用单声道。 My profiler shows that FieldInfo.GetValue() spends most of time in MonoField.CheckGeneric(). 我的探查器显示FieldInfo.GetValue()在MonoField.CheckGeneric()中花费了大部分时间。 And call to MonoField.GetValueInternal() is really fast but private! 而且对MonoField.GetValueInternal()的调用确实非常快捷,但是却是私有的! Of course I can use reflection to call this private method directly (because I don't that generic check) but call by reflection kills all performance boost. 当然,我可以使用反射直接调用此私有方法(因为我没有进行泛型检查),但是通过反射调用会杀死所有性能提升。

2) Is it possible to call this private method quickly (w/o reflection overhead and w/o modifying Mono sources to make it public)? 2)是否可以快速调用此私有方法(不增加反射开销,并且不修改Mono资源以使其公开)?

You can emit the il to do the get value. 您可以发出il来获取值。 So after the first call to any type you cache the IL however if you have a lot of types this might not work. 因此,在首次调用任何类型之后,您都将缓存IL,但是,如果您有很多类型,则可能不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM