I'm working on large tree with and I noticed that calling EnableBehavior when spawning new agents is allocating a lot of memory (~0.3MB) and is taking 30ms. It seems that it's caused by this method:
TaskContainsMethod(string methodName, Task task)
and the reflection used here:
MethodInfo method = task.GetType().GetMethod(methodName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
I'm wondering if this could be improved somehow for example:
- if the result could be cached by type, so that reflection could be avoided when checking multiple tasks of the same type
- currently GetMethod is called 12 times per task for different methodName, perhaps GetMethods could be called instead, and then the result could be checked agains all 12 method names we're interested in
TaskContainsMethod(string methodName, Task task)
and the reflection used here:
MethodInfo method = task.GetType().GetMethod(methodName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
I'm wondering if this could be improved somehow for example:
- if the result could be cached by type, so that reflection could be avoided when checking multiple tasks of the same type
- currently GetMethod is called 12 times per task for different methodName, perhaps GetMethods could be called instead, and then the result could be checked agains all 12 method names we're interested in