less than 1 minute read

Reflection이 느린 이유

배경

  • CLR Type System Design Goals
    • Goals
      • Accessing information needed at runtime from executing (non-reflection) code is very fast.
    • Non-Goals
      • All uses of reflection are fast.
  • EEClass
    • MethodTable data are split into “hot” and “cold” structures to improve working set and cache utilization. MethodTable itself is meant to only store “hot” data that are needed in program steady state. EEClass stores “cold” data that are typically only needed by type loading, JITing or reflection. Each MethodTable points to one EEClass.

어떤 동작때문에 느린것인가?

  • Fetching the Method information
  • Argument Validation and Error Handling
  • Security Checks

Reflection에는 어느정도의 비용이 들어 가는가?

Reading a Property (‘Get’)

Method Mean StdErr Scaled Bytes Allocated/Op
GetViaProperty 0.2159 ns 0.0047 ns 1.00 0.00
GetViaReflection 197.9258 ns 0.2704 ns 923.08 0.01

Writing a Property (‘Set’)

Method Mean StdErr Scaled Bytes Allocated/Op
SetViaProperty 1.4043 ns 0.0200 ns 6.55 0.00
SetViaReflection 287.1039 ns 0.3288 ns 1,338.99 115.63

Tags: , , ,

Categories:

Source File: 2021-05-06-why-reflection-is-slow.md

Updated:

Comments