LoadCharacter() hogging server resources

This is more apparent on larger games, but you can see it on a simple baseplate.

I came across a script that was hogging server resources for short periods of time seemingly at random. After some investigation, I narrowed it down to being triggered by LoadCharacter(). I set up a loop in a testing game to test my theory and the results confirmed my suspicion, the spikes in server usage coincide with Player:LoadCharacter() being called (there was only one player in the game at the time).

I tested this on a blank baseplate and yielded less extreme results, the spikes would top out at about 1.5%. In an empty game of mine, these spikes end up coming in at 9-11% (this is where the below screenshot was taken). In a full game of mine, the spikes can clock in anywhere from 40-60%, which is why it grabbed my attention.

If you throw the following code into a script in ServerScriptService you should be able to replicate the problem. From what I can tell, the size / busyness of the game directly correlates to the size of the spike that occurs upon LoadCharacter() being called.

while wait(2) do for _, Player in pairs(game.Players:GetPlayers()) do Player.TeamColor = BrickColor.random() wait(2) Player:LoadCharacter() end end
16 Likes

I’ve had issues in the past where calling LoadCharacter on the entire server (e.g. spawning everyone for a battle match) caused the server to seize up for seconds at a time, during which player movement and other things wouldn’t be replicated to clients at all. Not sure why it has performance issues like that.

5 Likes

the plot thickens

2 Likes

Who should I tag to get this looked at, this is a big issue.

What happens if you Destroy the character manually before any LoadCharacter calls?

if Player.Character then
   Player.Character:Destroy()
end
Player:LoadCharacter()

Does this make the problem less severe or does it have no significant effect?

No effect.

I wonder what the difference between these cases is. Do any of these games allow gear? Is the spawn area in any of the games complex (e.g Spawning around complex unions that collisions must be calculated with) ? Is the spike any different based on how long the server has been running?

In my case (the one I mentioned earlier), it was pre-unions. There were no complex physics, but there were tools (3 - LinkedSword, and two guns). Guns were about 20 parts each. The performance issues started before characters respawned – when LoadCharacter was called on the whole server, your character would disappear and then you’d be characterless for seconds while waiting for other users to spawn before it finally being your turn and spawning in. The server size was 30 IIRC.

No gear, the spawn area doesn’t contain any hugely complex unions (if any at all). I can’t tell if the spikes correlate with the server age, but it’s entirely possibly.

This is still a problem that’s negatively affecting my games, nothing seems to have changed since I first posted about the issue.

I’m still have lag issues with LoadCharacter(). It’s really, really bad at Barrel Blast.

However, I am having latency spikes on the Client that are much more noticeable than the server. In the activity monitor, the Replicator is spiking up.

Just to make sure, are you calling Player:LoadCharacter(false)? You should never set this argument to false, or performance will be really bad. We are planning to remove this parameter in the future. I have updated the wiki article mentioning this too.

I didn’t even realize there was a parameter for this function. I’ve not been using it but have been experiencing large lag spikes in conjunction with this.

I had no idea there was a parameter. We are not using it.

Here is the place where I get the issue:

It’s possible the issue is with our code but the script monitor isn’t showing it and the Replicator spikes when the lag occurs.

How many people need to have their characters loaded at once before this becomes an issue?

I think your issue may not be related to LoadCharacter and instead be related to sound loading. I have PMed you more details.

1 Like

The example on the wiki says Player:LoadCharacter() (which is false not true)

The inGame parameter defaults to true.

1 Like

If you LoadCharacter an entire server ( ~ 20 players ) the server will freeze for about 20 seconds until all characters are respawned

2 Likes

Hello darkness my old friend

one vertical bar=100ms. I just loaded up a baseplate and ran the stuff in the command bar. This is a test server.

3 Likes