Some question regarding the use of reflection?

Some question regarding the use of reflection?

Old forum URL: forums.lhotka.net/forums/t/741.aspx


RangerGuy posted on Thursday, July 27, 2006

I've read that reflection can be very powerful but comes at a cost in terms of performance.

There is an aspect of our business framework where we could really benefit from using reflection. This area of the framework would be used almost everytime a user submits a page or tries to persist thier data.

We would like to use reflection to execute methods on objects based on the criteria previously entered in the system by an administrator. The system settings are dynamic so we can not write code to handle them.

Would reflection be a poor solution?

hurcane replied on Thursday, July 27, 2006

You must always consider the benefits against the costs. You already know your benefits. You don't know your costs. The only way to know your costs is to measure performance with the reflection code and determine whether the time it takes to execute is worth it.

Since your reflection is going to happen along with network traffic (i.e. submiting a page, persisting data), it's likely that the extra time spent doing reflection is going to be a miniscule percentage compared to the overall time spent making a network round-trip and possibly making database calls.

ajj3085 replied on Thursday, July 27, 2006

Without knowing more, its hard to say if reflection would work well or not.

You can offset reflection as well; the first time you refelect you could cache the results somehow, and then next time its a quicker lookup.  You also could using Emit to create some classes on the fly based off the reflected type.  These would execute as fast as native code.

Andy

newbie replied on Thursday, July 27, 2006

Don't know too much about Reflection, but here is an article I came across that uses and alternate method which might be useful?

http://www.codeproject.com/csharp/FastMethodInvoker.asp

Copyright (c) Marimer LLC