fix(memory): 宫格缩略图 settle 加 3 路并发闸门(v3.26.114)
113 稳态已达标(60s heap 16MB、imgBigN 0、imgDataMB 0.5MB),但 ready-2s 出现 370MB 瞬时峰: settle() 为每个图库条目把原图读成 dataURL(2~8MB),上百条同时等待 ⇒ 瞬时几百 MB。 加 3 路并发闸门,峰值随并发走而不随条目数走。
This commit is contained in:
1 parent
acd1e0fa96
commit
ff3e5bc8df
6 files changed
+31
-9
No files matched your search
+19
-5
@@ -164,6 +164,20 @@
|
||||
// v3.26.113:宫格只接受**显示缩略图**,绝不把原图 base64 交给 <img>。
|
||||
// 原来 thumbFor 直接 display(原图dataURL),而 display 首帧返回原图 ⇒ 111 张 2~8MB 常驻 DOM(Windows 实测 260MB)。
|
||||
const HUGE_DATA = (u) => typeof u === 'string' && u.indexOf('data:') === 0 && u.length > 524288
|
||||
// v3.26.114:settle 会把条目原图读成 dataURL(2~8MB)。上百个条目同时进 settle,
|
||||
// 瞬时就是几百 MB(113 实测 ready-2s 370MB)。这里限 3 路:峰值随并发走,不随图库条目数走。
|
||||
const settleSlots = { n: 0, wait: [] }
|
||||
const withSlot = (fn) => new Promise((res, rej) => {
|
||||
const run = () => {
|
||||
settleSlots.n++
|
||||
Promise.resolve().then(fn).then(res, rej).finally(() => {
|
||||
settleSlots.n--
|
||||
const nx = settleSlots.wait.shift()
|
||||
if (nx) nx()
|
||||
})
|
||||
}
|
||||
if (settleSlots.n < 3) { run() } else { settleSlots.wait.push(run) }
|
||||
})
|
||||
async function thumbFor (name, extra) {
|
||||
const e = extra || {}
|
||||
const f = (Array.isArray(e.outputs) ? e.outputs : []).find((x) => x && x.name === name)
|
||||
@@ -179,13 +193,13 @@
|
||||
}
|
||||
return ''
|
||||
}
|
||||
if (f.data) return settle(f.data)
|
||||
if (f.data) return withSlot(() => settle(f.data))
|
||||
if (f.thumbHash && typeof e.galleryThumb === 'function') {
|
||||
try { const v = await e.galleryThumb(f.thumbHash); if (v) return settle(v) } catch (err) { /* 继续本地原图 */ }
|
||||
try { const v = await e.galleryThumb(f.thumbHash); if (v) return withSlot(() => settle(v)) } catch (err) { /* 继续本地原图 */ }
|
||||
}
|
||||
const local = await localCopySrcOf(f)
|
||||
if (local) return settle(local)
|
||||
return settle(f.url || '')
|
||||
const local = await withSlot(() => localCopySrcOf(f))
|
||||
if (local) return withSlot(() => settle(local))
|
||||
return withSlot(() => settle(f.url || ''))
|
||||
}
|
||||
|
||||
return { archiveEntryNow, wasArchived, notifyChanged, localCopySrcOf, prepareInsert, gridSpots, nodeImageOf, thumbFor }
|
||||
|
||||
Reference in new issue
Block a user