Polarith AI
1.7
AIMPerformance Class Reference

Description

This component dramatically improves the performance in scenes by optimizing the update calls of agents (Pro only).

First, an active AIMPerformance object in a scene overrides the update mechanism of every single agent. That means every agent stops using its own update method and is processed by this component using the unified UpdateFrequency. Thus, only one instance of AIMPerformance is allowed within a scene for preventing multiple updates for one single agent.

With PerformanceType.LoadBalanced, agent updates are distributed equally over the available frames instead of having large updates in the given UpdateFrequency. The TargetFps parameter is used to determine the optimal update distribution based on the actual frame rate. PerformanceType.LoadBalanced works for non-multithreaded agents only and is the default setting of this component.

If AIMPerformance is present in the scene, every agent which is both AIMContext.Threaded and AIMContext.ThreadSafe gets evaluated in parallel, whereby all available agents are distributed equally over the configured Threads. Non-multithreaded agents are updated with the same specified UpdateFrequency within a coroutine. As for single agents, if the UpdateFrequency is equal to or lesser than 0, Unity's update method is used instead.

An AIMContext is considered AIMContext.ThreadSafe if all of its associated AIMContext.Behaviours are also thread-safe. Through multithreading, the overall system might run about two to three times faster than without multithreading. Of course, this mainly depends on the number of agents, active behaviours, the number of receptors per sensor and the number of perceived objects per agent. Multithreading performs best on large-scale scenes which have got hundreds of agents running simultaneously. Furthermore, multithreading is not the holy performance grail for all purposes. When you have got a scene with lots of agents and every agent is able to perceive all other agents and/or many other objects, you might consider a smart level structure managing which objects are relevant for an agent. Therefore, you might use the SpatialPartitionType.RegularGrid method available in the AIMSteeringPerceiver or custom octree or quadtree structures. Furthermore, you have to keep in mind that you better do not resize the AIMEnvironment.GameObjects list too often but just reset its references (to null) in order to prevent expensive memory allocations.

Inheritance diagram for AIMPerformance:
AIMContextEvaluation

Public Fields

PerformanceType Performance = PerformanceType.LoadBalanced
 Determines the optimization method to be used for agent updates. More...
 
int Threads = 4
 Determines how much threads should be used. More...
 
float UpdateFrequency = 20.0f
 Specifies how often agents should be updated per second. More...
 
float TargetFps = 60.0f
 A value used as a reference for the PerformanceType.LoadBalanced feature. More...
 

Protected Static Fields

static int instancesCount = 0
 Memorizes the current number of AIMContextEvaluation instances. More...
 

Properties

static int InstancesCount [get]
 The number of AIMContextEvaluation instances which are currently present within the scene (read only). More...
 
Imprint