Performance impact?

  • Thread starter Thread starter Oscar Thornell
  • Start date Start date
O

Oscar Thornell

Hi!

I am wondering about the cost of the following code snippet..
//
GenericIdentity identity =
(GenericIdentity)System.Threading.Thread.CurrentPrincipal.Identity;

Thanks
/Oscar
 
Oscar Thornell said:
Hi!

I am wondering about the cost of the following code snippet..
//
GenericIdentity identity =
(GenericIdentity)System.Threading.Thread.CurrentPrincipal.Identity;

It will cost a little, there are several locks and some pinvoke, but its
probably not exceptionally expensive. Are you going to be doing it often
enough for it to matter?
 
Let´s put it like this...
Every request into the business layer (and below)) will be authorized by
checking the current role.
We have very good performance today by using a combination of
"CurrentPrincipal" and caching. I am however looking for ways to improve the
design.. (maybee with Spring and IoC...)

Do you have som links that explain what goes on under the hood in this case?

/Oscar
 
Let´s put it like this...
Every request into the business layer (and below)) will be authorized by
checking the current role.
We have very good performance today by using a combination of
"CurrentPrincipal" and caching. I am however looking for ways to improve the
design.. (maybee with Spring and IoC...)

Do you have som links that explain what goes on under the hood in this case?

Well, Reflector would tell you whether or not caching occurs in the
thread itself. It's probably not an issue though - I've just timed
getting the principal's identity on my laptop, and a hundred million
calls takes about 6 seconds. Now, that's all on the same thread, with
no changes to the principal - but it gives an idea of how cheap it is.
Unless your business layer calls do very, very little indeed, it's
unlikely to be an issue. Certainly if there's *any* network activity
going on (eg database calls) I'd be very surprised if that didn't make
the identity check totally insignificant.

The key thing is to measure it. Try running tests without any security
involved, and the same tests with the security checks. I suspect you'll
find it's not a significant part of the performance of the system.
 
Ok! Thanks!

/Oscar

Let´s put it like this...
Every request into the business layer (and below)) will be authorized by
checking the current role.
We have very good performance today by using a combination of
"CurrentPrincipal" and caching. I am however looking for ways to improve
the
design.. (maybee with Spring and IoC...)

Do you have som links that explain what goes on under the hood in this
case?

Well, Reflector would tell you whether or not caching occurs in the
thread itself. It's probably not an issue though - I've just timed
getting the principal's identity on my laptop, and a hundred million
calls takes about 6 seconds. Now, that's all on the same thread, with
no changes to the principal - but it gives an idea of how cheap it is.
Unless your business layer calls do very, very little indeed, it's
unlikely to be an issue. Certainly if there's *any* network activity
going on (eg database calls) I'd be very surprised if that didn't make
the identity check totally insignificant.

The key thing is to measure it. Try running tests without any security
involved, and the same tests with the security checks. I suspect you'll
find it's not a significant part of the performance of the system.
 
Back
Top