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

Ratelimit MeshUpdateQueue::cleanupCache() runs

This commit is contained in:
sfan5 2022-07-31 23:10:18 +02:00
parent 6ec6acc539
commit 4c1ef1b72b
2 changed files with 12 additions and 1 deletions

View file

@ -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;