1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Cache serialized mapblocks during sending

This reduces the
(absolute) time spent in Server::SendBlocks() from 700ms to 300ms
(relative) share of MapBlock::serialize() from 80% to 60%
in a test setup with 10 players and many block changes
This commit is contained in:
sfan5 2022-05-05 22:03:49 +02:00
parent 7fff9da71d
commit 1fa4f58080
2 changed files with 45 additions and 13 deletions

View file

@ -424,6 +424,16 @@ private:
std::unordered_set<session_t> waiting_players;
};
// the standard library does not implement std::hash for pairs so we have this:
struct SBCHash {
size_t operator() (const std::pair<v3s16, u16> &p) const {
return (((size_t) p.first.X) << 48) | (((size_t) p.first.Y) << 32) |
(((size_t) p.first.Z) << 16) | ((size_t) p.second);
}
};
typedef std::unordered_map<std::pair<v3s16, u16>, std::string, SBCHash> SerializedBlockCache;
void init();
void SendMovement(session_t peer_id);
@ -484,7 +494,9 @@ private:
float far_d_nodes = 100);
// Environment and Connection must be locked when called
void SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver, u16 net_proto_version);
// `cache` may only be very short lived! (invalidation not handeled)
void SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver,
u16 net_proto_version, SerializedBlockCache *cache = nullptr);
// Sends blocks to clients (locks env and con on its own)
void SendBlocks(float dtime);