Thursday, February 28, 2008

I'm a big reflection fan. However, reflection is slow and (for certain actions) requires full-trust. That's a big issue, since that means you can not use it in an unsigned xbap or whatever.

People are finding some cool ways to work around reflection where they can.

Ayende talks about the performance implications of creating objects here, and concludes that reflection might be slow, but you should ask yourself if you really care. If you do, he shows how to use dynamic methods to do the creation for you.

Roger Alsing takes it one step further, and uses Linq to build an expression tree to access private fields. Radical!! I love it. Read it here.
Also note his performance gains:

This approach is also much faster than Reflection.FieldInfo.
I made a little benchmark where I accessed the same field a million times.

The Reflection.FieldInfo approach took 6.2 seconds to complete.
The Compiled lambda approach took 0.013 seconds to complete.
That’s quit a big difference.

But keep in mind that actually compiling the expression is many times slower than reflection.

Thursday, February 28, 2008 11:05:11 AM (Romance Standard Time, UTC+01:00)
I've posted a followup on Ayende's post using Linq expression trees
http://rogeralsing.com/2008/02/28/linq-expressions-creating-objects/

So you can get similair performance as IL emit using compiled expression trees.

//Roger
Sunday, March 02, 2008 5:50:52 PM (Romance Standard Time, UTC+01:00)
I've written an article about a fast dynamic factory by using Reflection.Emit over a year ago and it's nice to see that Ayende's implementation has a lot in common with my aproach.

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):