Merge pull request #54 from ldmonster/fix/memory-pressure-and-hardening

[fix] Memory, Threading & Network Hardening
This commit is contained in:
Kelsi Rae Davis 2026-04-06 13:45:31 -07:00 committed by GitHub
commit 20e016798f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 333 additions and 25 deletions

View file

@ -1212,6 +1212,28 @@ void TerrainManager::workerLoop() {
break;
}
// --- Memory-aware throttling ---
// Back-pressure: if the ready queue is deep (finalization can't
// keep up), or the system is running low on RAM, sleep instead
// of pulling more tiles. Each prepared tile can hold hundreds
// of MB of decoded textures; limiting concurrency here prevents
// WoWee from consuming all system memory during world load.
const auto& memMon = core::MemoryMonitor::getInstance();
if (memMon.isSevereMemoryPressure()) {
// Severe pressure — don't pull ANY work until main thread
// finalizes tiles and frees decoded texture data.
lock.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(200));
continue;
}
if (readyQueue.size() >= maxReadyQueueSize_ || memMon.isMemoryPressure()) {
// Moderate pressure or ready queue is backing up — sleep briefly
// to let the main thread catch up with finalization.
lock.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
continue;
}
if (!loadQueue.empty()) {
coord = loadQueue.front();
loadQueue.pop_front();