#Which do you think is more performing for update method?

1 messages · Page 1 of 1 (latest)

heady marlin
#

hi guys. Which do you think is more performing for update method?

update(){
if(shouldIRunTheFunction)
  theFunction();
}

or

List<Action> functions = new List<Action>();

update(){
foreach (Action func in functions)
   func();
}
//when i need to run function in every frame
functions.Add(theFunction);

//when the function is not necessary
functions.remove(theFunction);

or i can use the for loop at the "action list" codes

plucky ridge
pseudo wigeon
plucky ridge
#

theoretically the list method will be faster as it has to do less work (fewer pipeline flushes / cache misses)

heady marlin
#

i wonder if there is a more performing way to run a function in every frames when want and don't run when i don't want but don't check it so don't make effort

#

it's like put something in update method and remove when i want

plucky ridge
#

if you enable disable the component the engine will probably remove it from its internal update stack... in any case it won't have update called anymore

#

unless you are very deep into optimising a very large number of gameobjects that update every frame, i would not worry about such checks.

#

enabled components with an update method are the limiting factor more so than the check whether the update should do something... if you manage those update calls yourself in a more cache/pipeline friendly way you can get significanly more objects into a scene... those just can't be active GameObjects as that would negate your optimisations again.

#

deep down in low-level unsafe, unmanaged, pointer-based C# you can squeeze a lot of performance out of your CPU...

heady marlin
#

no i'll control them in a varaible. u know get and set functions. if a bool varaible get true, run the update, if not close the update. btw yea enabling and disabling a component is more logical.
(sory for my english)

#

so with varaibles, the checking system doesn't take so much cpu performance