MethodInfo.Invoke performance issue

前端 未结 3 2017
-上瘾入骨i
-上瘾入骨i 2020-12-06 00:19

I am reading and writing data to and from a file. The data in the file can be floats, doubles, ints etc. The type is not known until runtime. I will refer to data type store

3条回答
  •  无人及你
    2020-12-06 01:16

    Yes, this is due to the fact that the reflection API is thousands of times slower than direct method calls. There are some interesting techniques to work around this however. Check out Jon Skeet's article on using delegates to cache reflection.

    There is a static setup cost but once you have done that the time to invoke the delegate repeatedly is equivalent to virtual method calls.

    There are also some pre-packaged frameworks to achieve the same thing.

提交回复
热议问题