is it me or is there a Huge Allocation problem?

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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17228
    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?

      #17234
      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!

        #17233
        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 🙁

          #17232
          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!

            #17231
            golonko
            Participant

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

              #17230
              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).

                #17229
                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.