Possible performance improvement

szczepan

New member
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
 
And one more idea- This one will be more complicated to implement, using behavior tree reference i s de of another behavior tree is currently very slow. One thing I was able to do is instead of passing parameters to that task (which involves a lot of slow type conversions) it's better to save variables to some monobehavior before entering external tree and then reading from it inside external tree. Still it's not solving everything-especially it would be nice if such tree could be preinitiated in a poll rather than de serialized during EnableBehavior
 
Thanks for your suggestions! The first post will be implemented in the next update.

For your second one I do have plans on adding that to version 2. I'd like to have local, GameObject, scene, and global variables.
 
Top