FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.39k stars 149 forks source link

Cache transforms in NetworkTransform, improving NetworkTransform performance by some 30-40% #742

Closed FREEZX closed 3 months ago

FREEZX commented 3 months ago

I have tested caching the transform in NetworkTransform, and in my project that has about 350 NetworkTransforms active across multiple world chunks, this change improved the NetworkTransform's TimeManager_OnPostTick function's performance about 30-40% (from taking 1.3ms to taking about 0.9ms) because accessing component.transform repeatedly has some minor performance implications that can quickly add up, and this is quite a hot path.

FirstGearGames commented 3 months ago

I am not seeing any difference in my tests but it's quite possible my hardware is too fast for the caching to make a measurable difference. None the less it certainly cannot hurt so we'll get this merged in.

FREEZX commented 3 months ago

I've been testing on a real project with a whole bunch of different NetworkTransforms and a big number of other NetworkBehaviours, TimeManager_OnPostTick was taking a lot of time, and the game is fairly CPU-bound, so shaving off every bit of extra CPU performance we can get is super important. This change made an actual big difference in our use case.