2

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)?

Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112

1 Answers1

1

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.

rerun
  • 25,014
  • 6
  • 48
  • 78
  • +1: Sound interesting, could you please elaborate a bit because I never used IL directly. Is it portable (would work in Mono)? – Andriy Tylychko Oct 31 '13 at 16:47
  • IL is the basis of .net so it better be. I would have suggested just using dynamic but I don't know if mono supports it look here http://stackoverflow.com/questions/7478387/dynamic-and-performance – rerun Oct 31 '13 at 16:52