Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkEarlyUpdate causing game to lag significantly ON ANDROID #2934

Open
LightPat opened this issue May 23, 2024 · 4 comments
Open

NetworkEarlyUpdate causing game to lag significantly ON ANDROID #2934

LightPat opened this issue May 23, 2024 · 4 comments
Assignees
Labels
priority:high stat:imported Issue is tracked internally at Unity type:bug Bug Report

Comments

@LightPat
Copy link

LightPat commented May 23, 2024

Description

NetworkEarlyUpdate taking WAY too long in profiler.

image

This happens every 3-5 frames in my game, ONLY ON ANDROID. To be clear, I'm not assigning values to a FixedString network variable frequently anywhere in my code. Yet, this network message is taking up so much frame time so frequently (25-35%). I think this might be related to #2920 , as my project was suffering from that bug too. On 1.8.1, I also have this problem.

Environment

  • OS: Windows 10
  • Unity Version: 2021.3.38f1
  • Netcode Version: 1.9.1, 1.8.1

Additional Context

This is the code for my NetworkString struct I'm using now, since FixedString doesn't work on its own. See issue #2920
image

@LightPat LightPat added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels May 23, 2024
@LightPat LightPat changed the title NetworkEarlyUpdate & FixedStrings causing game to lag significantly May 23, 2024
@LightPat LightPat changed the title NetworkEarlyUpdate & FixedStrings causing game to lag significantly ON ANDROID May 25, 2024
@LightPat
Copy link
Author

After further analysis, it appears that my lag is coming from too many client RPC calls. When I have 8 players or so, each time they play an attack (which happens pretty frequently it's a hack and slash game), it adds to the message queue. I can have all the players connected, and if I disable the attacking RPCs, my FPS is stable, and network early update no longer takes up 30% of frame time (0-3%). I debugged that the RPCs aren't getting sent every frame, so I'm confused as to why this is happening still

@LightPat
Copy link
Author

Also, this problem occurs whether using the new [Rpc] attribute or the legacy [ServerRpc] and [ClientRpc] attributes

@fluong6 fluong6 added stat:import priority:high stat:imported Issue is tracked internally at Unity and removed stat:awaiting triage Status - Awaiting triage from the Netcode team. stat:import labels Jun 3, 2024
@LightPat
Copy link
Author

LightPat commented Jul 8, 2024

Updating this issue as I have progressed in development in our game

When we are the host:

  • NetworkPreUpdate takes 15-20% of frame time (14-20 avg ms).
  • Most of the usage in NetworkPreUpdate comes from NetworkBehaviour.NetworkBehaviourUpdate/NetworkBehaviour.VariableUpdate()
  • NetworkEarlyUpdate takes 0% of frame time (0.05 avg ms).

When we are a client connected to a remote server:

  • NetworkPreUpdate takes 10-15% of frame time (every 1-3 frames, whenever a tick is processed) (48-60 avg ms)
  • NetworkEarlyUpdate takes 30-45% of frame time (170 avg ms).

It appears that this frame time is simply caused by NetworkVariable updates and RPC calls. When I'm just moving through the world my frame rate is stable with no issues. The frame drops only occur when other players that are connected perform actions.

Frame drops also occur on the client whenever an RPC is sent from a client to the server. I would attach my profiler data (deep profiling), but that's many GBs of data

This was tested with 1 remote player owned by the client and 3 player bots that were owned by the server in both cases.

@LightPat
Copy link
Author

After switching our scripts to mainly use network variables instead of RPC calls wherever possible, performance is better, however it's still not ideal. I attached a picture of the profiler when in a game with 8 players connected.
image
image
Notice how many calls to TrackNetworkVariableDeltaRecieved there are, as well as other functions. I was told that updating networkvariables in the update() function is totally okay, and that the changes would be collected on the next tick. Could it be that I'm assigning values too often?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:high stat:imported Issue is tracked internally at Unity type:bug Bug Report
3 participants