diff options
author | sfan5 <sfan5@live.de> | 2022-05-05 22:03:49 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2022-05-08 19:12:10 +0200 |
commit | 1fa4f58080b068920d7611291709377072d0cd00 (patch) | |
tree | f036bfc98dfb8cbf96dc860ced9ae6e4b4dac33d /src/server.h | |
parent | 7fff9da71d2de352e0afea7482fc2e26534a51a4 (diff) | |
download | minetest-1fa4f58080b068920d7611291709377072d0cd00.tar.gz minetest-1fa4f58080b068920d7611291709377072d0cd00.tar.bz2 minetest-1fa4f58080b068920d7611291709377072d0cd00.zip |
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
Diffstat (limited to 'src/server.h')
-rw-r--r-- | src/server.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/server.h b/src/server.h index 5090a3579..b1b9675d9 100644 --- a/src/server.h +++ b/src/server.h @@ -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); |