playMaker

Author Topic: Performance Memory Fsm Actions/Events/Variables  (Read 4160 times)

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Performance Memory Fsm Actions/Events/Variables
« on: November 08, 2016, 10:26:05 AM »
Hi there!

I am making a game where i have to instantiate a lot of gameobjects.
If these objects get instantiated with several fsm actions, events and variables on them, how is the memory behaviour? 

Thank's for your answer
stoffl   

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5082
    • View Profile
    • jinxtergames
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #1 on: November 08, 2016, 03:20:27 PM »
Hi,
Creating @ runtime is a bad thing, you should look into pooling

You can build a pool manager or get poolmanager 5
you can find actions for poolmanager 5 here or on the Ecosystem

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #2 on: November 08, 2016, 04:01:05 PM »
Thank's DjayDino for the answer and the links.
I currently have an array with all the objects at start and i just activate them.

I may asked the question wrong.
What i actually mean is: lets say a variable takes 1 KB in memory and a script 4KB on a gameobject.
This would be 5 KB per object for the fsm.
When i have 1000 objects will it be 5MB?
Also when i have the same action twice on a fsm will it double the memory, or is a fsm action referencing a script one time like a texture?

Thank you
stoffl
« Last Edit: November 08, 2016, 04:20:31 PM by stoffl »

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #3 on: November 08, 2016, 06:50:42 PM »
That's may be a silly question again with the scripts, i just wanted to know how you guys would manage a large amount of objects with fsm's on them. Do i have to take care about how many fsm's, variables, events and actions are on the objects in terms of memory and performance? At the moment i am trying to avoid a lot of different events and variables of the same type by reusing them.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5082
    • View Profile
    • jinxtergames
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #4 on: November 08, 2016, 10:29:32 PM »
Hi,
Good question actually.
I think an fsm works about the same way as you would place a script.
so each fsm would represent a script but i am not sure about that.
I think Alex can give you the best answer for this.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15318
  • Official Playmaker Support
    • View Profile
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #5 on: November 08, 2016, 11:56:01 PM »
Hi,

Yes, memory per object isn't shrinking with volume, that's true for every scripting technics.

Basically, any use of additional framework is having an impact on performances, wether it's a visual or pure scripted framework.

 handling large amounts of Object running Fsm requires step by step progressing and careful monitoring of performances using the profiler ( and using it well, which is where things go wrong, understanding the profiler is tricky and misleading without proper experience).

Your biggest issue isn't Fsm, it's what actions you are going to use and what you are going to do with them. Typically, finding a gameObject by name is costly and should be avoided at all cost. Do that 100 times per frame and you are sure to have bad perfs... but it's not linked to PlayMaker, it's linked to the Unity method itself that is known to be bad and should not be used within the GameLoop procedures.

The best advice I can give here is to not try to optimize your code and logic too early. Develop the feature you need for your game, and then optimize. Make it work first, then worry about optimizing exactly where you witness perfs issue, instead if guessing.

Also, in 99.99% of all the cases I witnessed over the years, I have found that performances is totally affected by bad shaders,camera effects... too much uncompressed textures, bad memory management  ( objects not being destroyed and are kept in memory, leading to crash eventually), etc etc. the cases where indeed Running an Fsm regardless of what's going to happen inside states being the culltrip is totally rare and on very very precise and known cases, typically, unlimited worlds loading on demand for, with massive ( several hundreds) amounts of prefabs being enabled disabled.

and even with this, we are talking about almost AAA companies looking at a 5% drop in FPS as a show stopper :) so in short you'll be fine using PlayMaker, embrace it! do what you need to do and simply monitor and profile regularly, you'll spot then in small iteration what went wrong. Along the way, yes you'll have to refactor and you'll gain experience on what to do what not to do, and that's best solved on a per case bases, with a very clear and precise/reproduceable issue, that's how you should tackle it ( how I tackle projects myself).


Bye,

 Jean

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #6 on: November 09, 2016, 09:10:08 AM »
Thank's for your answers!
This are really good tips jean, thank's!

Is there a method out there to messure the cost of a action or fsm proberly to create something like a performance chart?

I tried to create a scene where i want to messure the DropFPS for a action by looping through the same action several times... It don't seems to work very good and constant.

Let's say I have a target frame rate of 30 FPS and i would know that my looping fsm costs typically a 5 frames drop on a specific device which can play 60FPS. With that information i could define the fsm to just run when the frame rate is over 35FPS. Is that nonsense?

I had many performace issues and i tried working things out with the profiler. Mostly the issues where script increases (which i managed better by looping one fsm through multiple objects and having no actions on them whenever it's possible) The next big thing are graphic issues by activating a lot of gameobjects of an array at once, where i have for now a looping function with a waiting time of 1 frame (which is 0,034s for a 30FPS Target).

I am really thankful for any tips

stoffl

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15318
  • Official Playmaker Support
    • View Profile
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #7 on: November 11, 2016, 01:28:38 AM »
Hi,

 Perf chart per action is available in the Profiler, but yes, it's tricky to read and interpret data inside the profiler... no easy way around this...

you can listen to FPS, plenty of good assets on the asset store for this ( as you need to do some maths to get a good average value and smooth out the fps).

and then you can implement in your logic state switches depending on the fps, yes you can do that, but you can't within an action enable or disable execution based on FPS. I mean you can't as is, but you can certainly edit the actions to do so, but that requires editing the action in c#. and likely that means you need to duplicate it else PlayMaker update would overwrite your changes.

Bye,

 Jean

stoffl

  • Playmaker Newbie
  • *
  • Posts: 19
    • View Profile
Re: Performance Memory Fsm Actions/Events/Variables
« Reply #8 on: November 11, 2016, 04:52:51 AM »
Thank you jean!
Reading the profiler is really confusing and i hope to get a better practice handling things.
When i try to exterminate a spike, which somehow works, mostly another spike shows up, where it seems like that problem wasn't there before...

Bye
stoffl