verify-tiles: 给 DT1 库缓存加上限,避免跑全量时内存涨到数 GB

解码出来的 DT1 库很占内存(每个瓦片的块像素是 width×bitmapHeight 的 Uint8Array,一个库几十 MB),
原来无限缓存跑完 35 关会到 GB 级。与打包器一致地限制为同时 16 个库(比任何单一关卡类型用到的都多,
所以一关之内不会重复解码)。实测:全量跑 35 关峰值 RSS ≈ 1.9 GB,堆上限 2 GB,结束后立即回落。

顺带记录本地实测结果(7/7 通过):
  地面 28704 槽 / 墙 9514 槽 / 屋顶 492 槽
  地面槽类型全为 0(0 个错配)、墙/屋顶没画地面瓦片、looseRefs 0、missingTiles 0、位置公式 0 不符、
  411/411 个顶角右半都带了 type-4 伙伴、缺失伙伴 0
This commit is contained in:
troytt 2026-09-14 09:28:07 +08:00
parent 61c6691555
commit 46218f4280
1 changed files with 9 additions and 0 deletions

View File

@ -61,7 +61,12 @@ async function main(): Promise<void> {
archives.add(name, await MpqArchive.open(await fileSource(`${DIR}/${name}`)))
}
const tables = await loadActTables(archives)
// 解码出来的 DT1 库很占内存(每个瓦片的块像素是 width×bitmapHeight 的 Uint8Array,
// 一个库几十 MB),无限缓存跑完 35 关会涨到数 GB。跟打包器一样加个上限:
// 16 个库比任何单一关卡类型用到的都多,所以一关之内不会重复解码,内存曲线保持平坦。
const libraryCache = new Map<string, Dt1>()
/** 同时保留解码结果的 DT1 库上限。 */
const LIBRARY_CACHE_LIMIT = 16
let levels = 0
let floors = 0
@ -92,6 +97,10 @@ async function main(): Promise<void> {
try {
const decoded = decodeDt1(await archives.read(name))
libraryCache.set(name, decoded)
if (libraryCache.size > LIBRARY_CACHE_LIMIT) {
const oldest = libraryCache.keys().next().value
if (oldest !== undefined && oldest !== name) libraryCache.delete(oldest)
}
libs.push(decoded)
} catch { /* 缺库时 verify:acts 会报 */ }
}