perf(leafer-x-webfont): 按 family 内容指纹短路无变化的 loader.update

拖拽/缩放等操作每帧触发布局事件,防抖后仍会全量重扫并逐 family
调用 loader.update。新增 committed 指纹表:本轮收集的字符集与上次
提交一致时跳过 update,无文字变化的交互中 update 调用归零。
存字符串本身而非 hash,比较为 memcmp 级且零碰撞。
This commit is contained in:
崮生(子虚) 2026-08-15 19:13:36 +08:00
parent 64b9ca9a57
commit bf98a49a79

View File

@ -9,7 +9,7 @@
*
* / / / provider webfont-sdk
* Leafer
* - walk family
* - walk family family
* - property.change + layout.end
* - fontFamily 'xx.ttf' 'xx'canvas font
* - forceRender
@ -88,6 +88,13 @@ export class WebFontPlugin {
private mode: WebFontFontFaceMode
/** family -> 增量加载器(由 SDK 管理) */
private loaders = new Map<string, IFontFaceLoader>()
/**
* family -> loader
* /
* + loader.update diffupdate
* hash memcmp
*/
private committed = new Map<string, string>()
/** 防抖定时器 */
private debounceTimer: ReturnType<typeof setTimeout> | null = null
/** 解绑事件用的 id 列表 */
@ -193,8 +200,12 @@ export class WebFontPlugin {
walk(this.leafer)
for (const [, { loader, chars }] of groups) {
loader.update(charsToString(chars))
for (const [family, { loader, chars }] of groups) {
/** 内容指纹短路:本轮收集到的字符集与上次提交一致(拖拽等无文字变化的场景)时,跳过 loader.update */
const collected = charsToString(chars)
if (this.committed.get(family) === collected) continue
this.committed.set(family, collected)
loader.update(collected)
}
}
@ -307,6 +318,7 @@ export class WebFontPlugin {
this.offEvents = null
for (const loader of this.loaders.values()) loader.dispose()
this.loaders.clear()
this.committed.clear()
this.leafer = null
}
}