diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-04-04 10:56:46 +0200 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2018-06-03 17:32:00 +0200 |
commit | 396daf1be1c581da70eb40f7273fb7fad894de53 (patch) | |
tree | 5e3d3e8a22ab87639ac4ad19feb003e7996434bf | |
parent | fe41725e5027e90787f18088be82839760cccbb5 (diff) | |
download | minetest-396daf1be1c581da70eb40f7273fb7fad894de53.tar.gz minetest-396daf1be1c581da70eb40f7273fb7fad894de53.tar.bz2 minetest-396daf1be1c581da70eb40f7273fb7fad894de53.zip |
Huge LBM lookup performance improvement on mapblock loading (#7195)
* Huge LBM lookup performance improvement on mapblock loading
-rw-r--r-- | src/serverenvironment.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 8a66d4dfa..be1ddd7f0 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -262,16 +262,25 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) MapNode n; content_t c; lbm_lookup_map::const_iterator it = getLBMsIntroducedAfter(stamp); - for (pos.X = 0; pos.X < MAP_BLOCKSIZE; pos.X++) - for (pos.Y = 0; pos.Y < MAP_BLOCKSIZE; pos.Y++) - for (pos.Z = 0; pos.Z < MAP_BLOCKSIZE; pos.Z++) - { - n = block->getNodeNoEx(pos); - c = n.getContent(); - for (LBMManager::lbm_lookup_map::const_iterator iit = it; - iit != m_lbm_lookup.end(); ++iit) { - const std::vector<LoadingBlockModifierDef *> *lbm_list = - iit->second.lookup(c); + for (; it != m_lbm_lookup.end(); ++it) { + // Cache previous version to speedup lookup which has a very high performance + // penalty on each call + content_t previous_c{}; + std::vector<LoadingBlockModifierDef *> *lbm_list = nullptr; + + for (pos.X = 0; pos.X < MAP_BLOCKSIZE; pos.X++) + for (pos.Y = 0; pos.Y < MAP_BLOCKSIZE; pos.Y++) + for (pos.Z = 0; pos.Z < MAP_BLOCKSIZE; pos.Z++) { + n = block->getNodeNoEx(pos); + c = n.getContent(); + + // If content_t are not matching perform an LBM lookup + if (previous_c != c) { + lbm_list = (std::vector<LoadingBlockModifierDef *> *) + it->second.lookup(c); + previous_c = c; + } + if (!lbm_list) continue; for (std::vector<LoadingBlockModifierDef *>::const_iterator iit = @@ -279,7 +288,7 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp) (*iit)->trigger(env, pos + pos_of_block, n); } } - } + } } /* |