Using reflection in an asp.net web page ... performance

M

Mark

Am I out of my mind if I use Reflection everytime someone logs into our site
to get and track the current Major/Minor/Build/Revision version that the
person is viewing our site through? This information would then be logged
to a database along with some other information about the user.

Thanks in advance.

Mark
 
J

Jason Coyne Gaijin42

If you are only doing it once, in the sessionstart or something like
that, then you arent crazy, unless you site is getting hundreds of new
users per second.

IE, if you are running amazon.com, this is a bad idea. If you are
running some little dinky site, you are probably fine, as long as you
don't get /.ed

You do mean the version of your app right, not the version of their
browser? There is a much better way to get their browser info, and in
fact reflection won't work at all for that purpose.

I would think it would be easy to tell which version of your own app
you have running on the server. Do you have a large farm or something
where there might be multiple versions deployed?
 
R

Rick Strahl [MVP]

Hi Jason,

I'm sorry, but you might exaggerating the case just a little here. First
while reflection is slow compared to direct access or invokation it's not
THAT slow. For example, compare Reflection to a COM object invokation and
call in class ASP and it's outright fast.

Second, even if you don't use Reflection in your code, I'm sure there are
lots of places in the ASP.Net internal code as well in the .Net framework
itself that uses reflection to discover values dynamically at runtime.

I ran a few very simple tests just to verify that I'M not completely off my
rocker here, and sure enough adding a couple of reflection calls to even an
empty ASPX page resulted in nearly identical performance results in ACT. The
general variance of ACT in short tests actually had the reflection test
ahead in 1 of the tests - all the others were also very close with close 250
requests a second against the sample page.

THere's no doubt that relfection is slower than direct access, but there's
not even enough to worry about for making one or two Reflection per request.
You should worry about this for tuning in framework code that gets called
repeatedly and in a loop, but for single calls it's hardly a concern.

Regards,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top