is it me or is there a Huge Allocation problem?

NodeCanvas Forums Support is it me or is there a Huge Allocation problem?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #13414
    golonko
    Participant

    Hi there!

    I created quite a big behaviour tree to be used by up to a hundred agents in my game… and am in trouble now!
    Seems like NodeCanvas is allocating memory like crazy.
    At first i thought I simply shouldn’t use bound BB Parameters, as the getters and setters were first culprits, but after eliminating these, the allocations are still there.
    I’ve attached a test code I’m using with a very basic behavior tree running on a 1000 agents. Just a few nodes and they’re allocating over 400k every frame…

    What am I doing wrong?

    Attachments:
    You must be logged in to view attached files.
    #13423
    Gavalakis
    Keymaster

    Hello and sorry for the late reply (I was on a small vacation).

    Thanks for the unitypackage. It helped me locate the problem very easy. To fix this allocation issue, please open up BTDecorator.cs file and replace the property “decoratedConnection” getter with this piece of code instead:

    By the way, you don’t really need to use “Repeat Forever” as the root node of a BT, since that is already happening if the “Repeat” option is checked in the BehaviourTreeOwner inspector.

    Thanks a lot for the report!

    Join us on Discord: https://discord.gg/97q2Rjh

    #13429
    golonko
    Participant

    Thanks for your reply!
    That change helped with this particular problem.
    However in my actual project the problem is scattered across many different NodeCanvas elements.
    Ones that I am able to find quickly (and are most notorious) are:
    BBParameter.get_value / set_value (which internally calls allocationg MonoField.GetValueInternal())
    PrioritySelector.OnExecute (Allocates a lot with Enumerable.ToList())

    I can’t really make a unitypackage with the full tree, as it’s too closely tied to the rest of the project 🙁

    #13435
    Gavalakis
    Keymaster

    Hello again,

    Hmm.. BBParameter get/set_value property would only do this when a task is not using the generic version of BBParameter and which is the case mostly in the “Script Control/Multiplatform” tasks. If you are using a lot of Multiplatform Script Control tasks this is unfortunately something that can’t be avoided, but if you are targeting windows/mac, you don’t have to use the multiplatform versions. Let me know if that is the case indeed.

    The .ToList() in PrioritySelector.OnExecute is only called when the status of the node is “Resting” (like init), but it certainly a piece of code that could be improved I think. I will take a look into that.

    Let me know on the above.
    Thank you!

    Join us on Discord: https://discord.gg/97q2Rjh

    #13440
    golonko
    Participant

    Yes, my target platform is mobile, so I do have a lot of Multiplatform Script Control tasks

    #13446
    Gavalakis
    Keymaster

    Hello again,
    Even though Standalone targeted reflection tasks are very optimized, unfortunately with Multiplatform targeted Script Control tasks and due to reflection, allocations are inevitable due to value boxing. Thus if this is becoming a problem I would really suggest that you replace frequently used (and called) reflection-based tasks with custom tasks that call the function in question directly instead of through reflection.

    What exact kind of Script Control tasks do you use more often? (Execute Function, Implemented Action, Get/Set Property etc).

    Join us on Discord: https://discord.gg/97q2Rjh

    #13455
    golonko
    Participant

    Basically I’m using a mix of Execute Function and Implemented Action.
    Plus I have around 20 properties bound to variables in the blackboard that are used quite frequently

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.