fix(engine): use totalmem() instead of freemem() for memory scaling

Addresses review feedback: freemem() is misleading on macOS where
aggressive file caching reports low free memory even on high-spec
machines. Switched to totalmem()-based thresholds consistent with
calculateOptimalWorkers in parallelCoordinator.ts.

Thresholds now based on total RAM:
- <4GB total: GPU=512MB, V8=256MB, cache=32/128MB
- <8GB total: GPU=1024MB, V8=512MB, cache=64/256MB
- >=8GB total: unchanged (4096MB GPU, no V8 cap, 256/1500MB cache)
This commit is contained in:
Miguel Ángel
2026-05-25 15:37:13 -04:00
parent 2015d93d2a
commit c8ed90fa21
2 changed files with 18 additions and 19 deletions
+9 -10
View File
@@ -208,26 +208,25 @@ export const DEFAULT_CONFIG: EngineConfig = {
debug: false,
};
function getSystemFreeMb(): number {
function getSystemTotalMb(): number {
try {
const { freemem } = require("os") as typeof import("os");
return Math.floor(freemem() / (1024 * 1024));
return Math.floor(require("os").totalmem() / (1024 * 1024));
} catch {
return 8192;
return 16384;
}
}
function memoryAdaptiveCacheLimit(): number {
const free = getSystemFreeMb();
if (free < 2048) return 32;
if (free < 4096) return 64;
const total = getSystemTotalMb();
if (total < 4096) return 32;
if (total < 8192) return 64;
return DEFAULT_CONFIG.frameDataUriCacheLimit;
}
function memoryAdaptiveCacheBytesMb(): number {
const free = getSystemFreeMb();
if (free < 2048) return 128;
if (free < 4096) return 256;
const total = getSystemTotalMb();
if (total < 4096) return 128;
if (total < 8192) return 256;
return DEFAULT_CONFIG.frameDataUriCacheBytesLimitMb;
}