From 3abe47adc6d82c3b8d968eb572890e852b0288d6 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 03:26:39 -0700 Subject: [PATCH] perf(editor): periodic M2 model GPU cache cleanup every 30s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new persistent path->modelId map keeps models alive across rebuilds, which is great for the common case of moving an instance, but means models that lost all references stay in GPU memory forever. Added a 30s timer that calls m2Renderer->cleanupUnusedModels(), which has its own 60s grace period before actual eviction — so models stick around ~60-90s after their last instance is removed and then get freed. --- tools/editor/editor_app.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/editor/editor_app.cpp b/tools/editor/editor_app.cpp index 682ae4f0..0f64ebd4 100644 --- a/tools/editor/editor_app.cpp +++ b/tools/editor/editor_app.cpp @@ -119,6 +119,17 @@ void EditorApp::run() { // Refresh dirty terrain chunks refreshDirtyChunks(); + // Periodic GPU model cache cleanup. Models that lost all instances + // (e.g. user removed every spawn of one creature) get evicted after + // the renderer's grace period. Without this the editor would slowly + // accumulate GPU memory across long sessions. + static float modelCleanupTimer = 0.0f; + modelCleanupTimer += dt; + if (modelCleanupTimer >= 30.0f) { + modelCleanupTimer = 0.0f; + if (auto* m2 = viewport_.getM2Renderer()) m2->cleanupUnusedModels(); + } + // Track object and NPC counts separately size_t objCount = objectPlacer_.objectCount(); size_t npcCount = npcSpawner_.spawnCount();