简体   繁体   中英

How to speed up FieldInfo.GetValue() calls?

I'm using FieldInfo.GetValue() calls intensively in custom serializer. This function is really slow.

1) Is there a portable way to speed it up? I don't need any checks done by FieldInfo.GetValue() implementation, I just need to get that value quickly.

Now about a non-portable way. I use Mono. My profiler shows that FieldInfo.GetValue() spends most of time in MonoField.CheckGeneric(). And call to MonoField.GetValueInternal() is really fast but private! 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)?

You can emit the il to do the get value. So after the first call to any type you cache the IL however if you have a lot of types this might not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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