I am just starting to use DynamicProxy2 today. And I found that this led to a significant decrease in performance.
See code below. Test1 is 10 times slower than Test2.
Any tips on improving performance when using DynamicProxy?
class Program { public void Main() { for (int i = 0; i < 3; i++) { var stopWatch = Stopwatch.StartNew(); int count = 1 * 1000 * 1000; Test1(count);
Update:
On my machine, Test1 takes about 45 seconds, Test2 takes about 4.5 seconds. After reading Krzysztof KoΕΊmic , I tried setting NotifyPropertyChangedInterceptor to the Singleton scope:
builder.RegisterType<NotifyPropertyChangedInterceptor>().SingleInstance();
which saved me about 4 seconds. Test1 now takes about 41 seconds.
Update 2:
Test3 takes about 8.3 seconds on my machine. Thus, it seems that using only the Autofac or DynamicProxy function is not a very big problem (in my project), but combining them with each other will lead to a significant decrease in performance.
public void Test3(int count) { var generator = new Castle.DynamicProxy.ProxyGenerator(); for (int i = 0; i < count; i++) { generator.CreateClassProxy(typeof(TestViewModel), new NotifyPropertyChangedInterceptor()); } }
user593358
source share