Optimizations
CPU Performance Optimizations
Object Pooling
By default when a NetworkObject is Spawned/Despawned Fusion instantiates/destroys a Unity GameObject instance of that object. This is a very CPU expensive operation and causes allocations.
It is recommended to use a custom NetworkObjectProvider
for pooling the NetworkObject
instances.
More information can be found in the documentation page and the sample.
Tick Rate
In Server and Host Mode reducing the tick rate in the NetworkProjectConfig reduces CPU usage of gameplay code. The SendRate vales in the tickrate configuration do not have a significant impact on CPU performance.
Memory Optimization
Fusion pre-allocates a large amount of native memory in a heap. The size of this heap can be configured in the NetworkProjectConfig. The total size of the heap is PageCount * PageShift
. A heap is allocated for each network frame in memory. Since this network state is used for interpolation there are always multiple heaps allocated.
For applications with only a small amount of networked states the values can be reduced to safe memory. To do gradually reduce the PageCount
and PageShift
and play test the game in a realistic scenario. If Fusion runs out of memory it throws an OutOfMemoryException. (PageShift is recommended to be kept at 16Kb or higher).
Bandwidth Optimization
Optimizing bandwidth is important for a variety of reasons:
- It reduces the costs of your application by reducing bandwidth costs.
- It allows a larger percentage of your player base to play the game without encountering networking issues.
- Fusion's eventual consistency transfer algorithm works best when the snapshot size of network packets is less than MTU (Maximum Transmission Unit ~1280 bytes).
TargetFrameRate
On the server always set a target frame rate or Unity will run as many FPS as possible and use 100% CPU. There's no advantage to this since Fusion runs the gameplay simulation at a fixed tick rate in FixedUpdateNetwork.
The easiest way is to set the Application.TargetFrameRate
to the tickrate of Fusion like this:
Application.targetFrameRate = TickRate.Resolve(NetworkProjectConfig.Global.Simulation.TickRateSelection).Server;
Interest Management
Interest Management is the best way to drastically reduce bandwidth. It works for both Shared Mode and Host/Server Mode.
- Area of Interest allows you to only send players state about objects near them.
- The Interest Management Addon provides advanced tools to further optimize the Area of Interest shape for a player.
- Explicit Object Interest allows for fine-tuning problematic high bandwidth objects.
Send Rate
The send rate of Fusion can be reduced in the NetworkProjectConfig, so that Fusion only sends state over the network every 1/2, 1/4 or 1/8 tick. Reducing the send rate is a good way to reduce bandwidth without affecting the quality of the gameplay simulation (e.g. physics).
Avoid Strings
Avoid the usage of strings in RPCs and Networked Properties. Especially json, xml or other similar formats. Instead represent your data in a byte efficient structure by using a custom INetworkStruct.
Reliable Streaming API
Avoid sending large amounts of data over RPCs. Use the Data Streaming API instead. Read this page to understand which data transfer tool to use.
Back to top