Mirror icon indicating copy to clipboard operation
Mirror copied to clipboard

perf: Reduce Message Noise

Open MrGadget1024 opened this issue 10 months ago • 2 comments

Fixes #3828

High Ping frequency and TimeSnapshotMessage are only needed when NT's / PredictedRB's are actively used in the game

  • Prevents TimeSnapshotMessage sending when no NT's
  • Uses 2s Ping frequency when no NT's / PredictedRB's
  • NetworkTime has a static ulong highPingComponents
    • NTBase and NTHybrid increment / decrement via OnEnable / OnDisable
    • PredictedRigidbody increments / decrements via OnEnable / OnDisable
  • Tests updated to use DefaultPingInterval, now internal static instead of const

Tested with PlayerTest, Basic, BilliardsPredicted, and Room examples

  • PlayerTest works as expected using all NT prefabs
  • Basic example has no NT's, works as expected with low noise
  • BilliardsPredicted works as expected
  • Room example only uses NT in Game scene, not in Online scene
    • Logging shows the higher msg traffic in Game scene only, not in Online scene (correct)
    • Logging shows the reduced msg traffic when in Online Scene, even when switching back to Online scene from Game scene

MrGadget1024 avatar Feb 09 '25 15:02 MrGadget1024

Why is NetworkTime the class that is tracking the count of NetworkTransforms? Is it the only static class we have available at this time? I personally do not see a problem with it, but it seems kind of weird to look at. otherwise lgtm

realQuartzi avatar Feb 11 '25 21:02 realQuartzi

Why is NetworkTime the class that is tracking the count of NetworkTransforms?

A few reasons:

  • It's a neutral class that operates on both server and clients
  • Dependency chain accessibility from the Mirror.Components assembly
  • It has to know the count to return the correct PingInterval

Basically, any component (NT, PredictedRB, future others) has to tell NetworkTime they're alive, so the rest of Mirror uses the correct timing and sends the required messages.

MrGadget1024 avatar Feb 12 '25 06:02 MrGadget1024