diff options
author | sfan5 <sfan5@live.de> | 2022-07-31 23:10:18 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2022-08-02 11:58:26 +0200 |
commit | 4c1ef1b72bfb949b149e6eb75cb7082e31d22b5d (patch) | |
tree | c31f5ad46cee05a9f2d9053c8e61bfe7610d5259 | |
parent | 6ec6acc539321709ed8517f1a571777a04f5c24c (diff) | |
download | minetest-4c1ef1b72bfb949b149e6eb75cb7082e31d22b5d.tar.gz minetest-4c1ef1b72bfb949b149e6eb75cb7082e31d22b5d.tar.bz2 minetest-4c1ef1b72bfb949b149e6eb75cb7082e31d22b5d.zip |
Ratelimit MeshUpdateQueue::cleanupCache() runs
-rw-r--r-- | src/client/mesh_generator_thread.cpp | 12 | ||||
-rw-r--r-- | src/client/mesh_generator_thread.h | 1 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp index 5c3f4180b..9f4d98aac 100644 --- a/src/client/mesh_generator_thread.cpp +++ b/src/client/mesh_generator_thread.cpp @@ -50,7 +50,8 @@ QueuedMeshUpdate::~QueuedMeshUpdate() */ MeshUpdateQueue::MeshUpdateQueue(Client *client): - m_client(client) + m_client(client), + m_next_cache_cleanup(0) { m_cache_enable_shaders = g_settings->getBool("enable_shaders"); m_cache_smooth_lighting = g_settings->getBool("smooth_lighting"); @@ -231,6 +232,15 @@ void MeshUpdateQueue::cleanupCache() g_profiler->avg("MeshUpdateQueue MapBlock cache size kB", mapblock_kB * m_cache.size()); + // Iterating the entire cache can get pretty expensive so don't do it too often + { + constexpr int cleanup_interval = 250; + const u64 now = porting::getTimeMs(); + if (m_next_cache_cleanup > now) + return; + m_next_cache_cleanup = now + cleanup_interval; + } + // The cache size is kept roughly below cache_soft_max_size, not letting // anything get older than cache_seconds_max or deleted before 2 seconds. const int cache_seconds_max = 10; diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index 1b734bc06..e48c8334d 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -83,6 +83,7 @@ private: std::vector<QueuedMeshUpdate *> m_queue; std::set<v3s16> m_urgents; std::map<v3s16, CachedMapBlockData *> m_cache; + u64 m_next_cache_cleanup; // milliseconds std::mutex m_mutex; // TODO: Add callback to update these when g_settings changes |