pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
745 stars 112 forks source link

Use caching for Delegates #162

Closed jerviscui closed 2 years ago

jerviscui commented 3 years ago

If Aspect around the method, it will generate code like:

private object __a$_around_Method_100663472_w_0(object[] A_1)
{
    return this.Aspect.Around(new Func<object[], object>(this.__a$_around_Method_100663472_u), A_1);
}

The new Func<>() method will be exectued each time for create Delegate. How about use a static field cache Delegate,

static Func<@classType, object[], object> Func = this.__a$_around_Method_100663472_u;

private object __a$_around_Method_100663472_w_0(object[] A_1)
{
    return this.Aspect.Around(Func, this, A_1);
}

private static object __a$_around_Method_100663472_u(@classType instance, object[] A_1)
{
    return instance.__a$_around_Method_100663472_o((int)A_1[0]);
}

Do you think it's worth it?

pamidur commented 3 years ago

I like your idea! It looks doable, and will speed up execution especially on Around-heavy workloads. for instance methods we will need instance properties for static methods we will need static properies

pamidur commented 2 years ago

moved to #137