Spiking Rhino Proxy - Dynamic Proxy on CodeDOM

time to read 3 min | 570 words

What is Rhino Proxy?

Rhino Proxy is a little spike of mine, duplicating the work that has gone into Dynamic Proxy, but using CodeDOM, instead of Reflection.Emit.

The good news is that it took me about 3 days to duplicate nearly all the the functionality in Dynamic Proxy (I didn't do events, but it should be easy enough to do).

The really good news are that I managed to support generics methods interceptions, so interfaces like this are now valid:

public interface GetData
{
  T Get<T>(int id);
}

The bad? Here is Task Manager when I run the tests (~70) using Rhino Proxy:

(Image from clipboard).png

Here is Task Manage when I run the tests (same amount) using Dynamic Prxoy:

(Image from clipboard).png

The timing are also about twice as slow for the tests in Rhino Proxy vs. Dynamic Proxy. ~8 seconds for Dynamic Proxy vs. ~22 seconds for Rhino Proxy.

So, it is slower, more CPU intensive, and probably uses more memory. Why is it useful? It is useful because it is a proxy implementation that doesn't take a genius to build. It means that I may be able to resolve this bug which is hanging around for about a year.

I got a couple ideas about implementing offline caching and maybe doing batch compilations at once, which will probably be able to improve performance signifacntly. But I believe that Dynamic Proxy will always be faster, simply due to the lower level nature of Dynamic Proxy.

On a side note: More bad stuff is that whoever wrote the CodeDOM implementation for .Net 2.0 didn't do a good job at all. If I need to implement a method called "GetGoodTypeName" just so I will be able to handle generics types...
I also reflected over the implementation and recoiled in horror. How on earth is Microsoft going to maintain this stuff?
Take a look at "Microsoft.CSharp.CSharpCodeGenerator.GenerateTypeMember()", didn't it occur to them that a DOM is the perfect place to use a visitor, and not a lot of nested ifs? I'll probably post with more details soon about the failings of CodeDOM.

Anyway, I currently have all of Dynamic Proxy's tests working, and 426 (out of ~480) of Rhino Mocks' tests passing.  You can check the code here.

Take into account that this is just a (fairly big) spike, and I have no idea what its future will be.