perf: process 16 chunks/player/tick on dedicated server, revert async save

Chunk loading now batches up to 16 nearest-first requests per player per
tick on dedicated server (client stays at 1), improving tick recovery
time after player join.

Reverts the async save system -- the background thread snapshot/compress
path added complexity without measurable benefit. Autosave on Windows64
server now uses the standard synchronous flush like client, in
preparation for a proper async implementation from upstream.
This commit is contained in:
itsRevela
2026-04-05 15:56:39 -05:00
parent be17d4028f
commit 207d90de28
5 changed files with 36 additions and 192 deletions

View File

@@ -487,37 +487,52 @@ void PlayerChunkMap::getChunkAndRemovePlayer(int x, int z, shared_ptr<ServerPlay
}
// 4J - added - actually create & add player to a playerchunk, if there is one queued for this player.
// Processes up to CHUNKS_PER_PLAYER_PER_TICK requests per call to speed up initial chunk loading.
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
static const int CHUNKS_PER_PLAYER_PER_TICK = 16;
#else
static const int CHUNKS_PER_PLAYER_PER_TICK = 1;
#endif
void PlayerChunkMap::tickAddRequests(shared_ptr<ServerPlayer> player)
{
if( addRequests.size() )
{
// Find the nearest chunk request to the player
int px = static_cast<int>(player->x);
int pz = static_cast<int>(player->z);
int minDistSq = -1;
auto itNearest = addRequests.end();
for (auto it = addRequests.begin(); it != addRequests.end(); it++)
{
if( it->player == player )
for (int processed = 0; processed < CHUNKS_PER_PLAYER_PER_TICK; processed++)
{
// Find the nearest chunk request to the player
int minDistSq = -1;
auto itNearest = addRequests.end();
for (auto it = addRequests.begin(); it != addRequests.end(); it++)
{
int xm = ( it->x * 16 ) + 8;
int zm = ( it->z * 16 ) + 8;
int distSq = (xm - px) * (xm - px) +
(zm - pz) * (zm - pz);
if( ( minDistSq == -1 ) || ( distSq < minDistSq ) )
if( it->player == player )
{
minDistSq = distSq;
itNearest = it;
int xm = ( it->x * 16 ) + 8;
int zm = ( it->z * 16 ) + 8;
int distSq = (xm - px) * (xm - px) +
(zm - pz) * (zm - pz);
if( ( minDistSq == -1 ) || ( distSq < minDistSq ) )
{
minDistSq = distSq;
itNearest = it;
}
}
}
}
// If we found one at all, then do this one
if( itNearest != addRequests.end() )
{
getChunk(itNearest->x, itNearest->z, true)->add(itNearest->player);
addRequests.erase(itNearest);
// If we found one, process it and continue; otherwise done
if( itNearest != addRequests.end() )
{
getChunk(itNearest->x, itNearest->z, true)->add(itNearest->player);
addRequests.erase(itNearest);
}
else
{
break;
}
}
}
}