First off, I don't even pretend to have a good comprehension of how remoting works.

What I do know is that right now the compiler generated classes derive directly from Object, and somehow this is bad for remoting, instead they should derive from MarshalByReferenceObject.  On the surface that is a very simple change, but it has some possibly serious performance implications.

Memory-wise, MBRO adds only a little bit.  Certainly not enough to outweight the benefits of better remoting.  The penalty comes when accessing fields of MBRO objects.  The penalty is that every field access gets indirected through a method call.  The method call is not needed when accessing fields off of the this pointer.

With iterators, this is a non-issue because the fields are only accessed internally off of the this pointer.  Anonymous methods have the potential to be greatly impacted.  It's bad enough that a local is now heap based, but making a local access into a method call would just supprise too many people.

So is there a way to have the best of both worlds: fast access and easy remoting?  Here are the two ideas I've heard tossed around (well I guess one is mine):

  • Some keyword or syntax to specify whether a given anonymous method should be MBRO.  Then you, the programmer, can clearly decide if remoting is more important than accessing locals quickly.  The problem here is what syntax?
  • Base it on the containing object.  This seems like a way of allowing you to decide, but without any extra syntax.  The problem is that many classes derive from frameworks classes that have already made that decision (and probably for different reasons).

So here's your chance! Voice your thoughts and opinions.  Do you have a better idea?  Do you think I'm making a big deal over nothing?