Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any side effects to using MarshalByRefObject?

Tags:

c#

.net

remoting

I have a case where I have to use some classes across AppDomains. To make them work I have them inheriting from MarshalByRefObject. Everything with these classes work as expected. But these classes are used throughout our system, and 99% of the time these classes will be used within only one AppDomain. Are there any negative side effects from inheriting from MarshalByRefObject when using these classes within a single AppDomain?

Thanks,
Skip

like image 491
SkipHarris Avatar asked Sep 20 '13 20:09

SkipHarris


1 Answers

Certainly, MRBO has a substantial affect on the code generated by the jitter. Any access to a field of the class results in a call to a helper method implemented in the CLR instead of a single CPU instruction that accesses the field.

This is inevitable, only the CLR knows whether the object is actually a proxy or the real deal. And a proxy needs to emulate a field with a remoting call. If it is not a proxy then you still pay for the helper call overhead, an easy order of magnitude slower.

Whether that truly has an impact on your code is impossible to predict, we're talking about nanoseconds here. You only do something about it if the slowdown becomes noticeable.

like image 146
Hans Passant Avatar answered Sep 27 '22 22:09

Hans Passant