Update() performance #746
Closed
FREEZX
started this conversation in
Feature Request
Replies: 2 comments
-
Much more simplier fix for ppl who do not have libs. We had chat in DM in Discord with FGG. If someone needs it:
public override void OnStartClient()
{
base.TimeManager.OnUpdate += CustomUpdate;
}
public override void OnStopClient()
{
if (base.TimeManager != null)
base.TimeManager.OnUpdate -= CustomUpdate;
}
private void InvokeStartCallbacks_Prediction(bool asServer)
{
if (_predictionBehaviours.Count == 0)
return;
if (!asServer)
{
TimeManager.OnUpdate += TimeManager_Update;
PredictionSmoother?.OnStartClient();
}
} c) NetworkObject.Prediction.cs - goto method private void InvokeStopCallbacks_Prediction(bool asServer) //right below last one. private void InvokeStopCallbacks_Prediction(bool asServer)
{
if (_predictionBehaviours.Count == 0)
return;
if (!asServer)
{
TimeManager.OnUpdate -= TimeManager_Update;
PredictionSmoother?.OnStopClient();
}
} In my case i have 5k nobs in the scene and in my working machine with Ryzen 1700 i have huge boost in performance, 6.41ms vs 2.31ms PS. The boost will be as big as the number of nobs you have in the scene |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Just adding on to an existing issue I noticed:
#745
We are at a point where we're trying to squeeze out every bit of performance that may be on the table. I tried to change FishNet's updates to use a Manager instead of relying on Update() alone, and managed to shave off a small but cool ~0.3ms in my project (77 to 80 fps).
In our case I used an excellent but discontinued library called SwissArmyLib that we use for a bunch of stuff in the game - so I converted all FishNet classes that use Update to rely on their ManagedUpdateBehaviour - NetworkObject, NetworkBehaviour and NetworkTransform mainly.
https://swissarmylib-docs.readthedocs.io/en/latest/Events/ManagedUpdateBehaviour.html
The downside to this approach is that using this custom loop doesn't use the execution priority of the script file, but has support for a custom code-based priority. It also allows you to still use the normal Update() function of unity that respects execution priority, so final users wouldn't be affected by a change like this, but will get a little bit of performance from the Update change on the NetworkTransforms and NetworkObjects
Beta Was this translation helpful? Give feedback.
All reactions