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
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.
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.
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.