web-font/scripts/build_glyph_index.ts
崮生(子虚) 1ffb1632b2 glyph-match 重构: 锚点索引+聚类剪枝+串行事件收集, 修复响应双 header 截断
- 慢路径 subset(查询字+锚点字) 顺带建 .gidx, 冷启动 39.75s→0.43s
- 去 async generator/worker 池/流式 pipeTo: LLRT 下非确定性饿死/segfault
- eventsCache(fontPath+查询签名 LRU64): 重复查询免裁剪, 稳态 42ms
- server 层 _bodyBytes 通道: header+body 单帧写回 + Content-Length
- 修复 bodyBytes 分支头部双写导致响应尾部截断(done 事件丢失)
- tcp 层 fire-and-forget write, close 只 end 不 destroy(保写缓冲)
- 慢路径并发度 GLYPH_MATCH_SLOW_CONCURRENCY 可配(默认1)
- 聚类排序+剪枝(PRUNE_MARGIN=0.35)减少冷路径裁剪量
2026-11-02 20:26:58 +08:00

43 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 全量预建字形索引:遍历字体目录,逐字体构建 .gidx(走内存闸门,一次一个)。
* 用法:pnpm exec tsx scripts/build_glyph_index.ts
*/
import "../backend/server/node";
import { readdir } from "../backend/interface";
import { fontDirs } from "../backend/config";
import { buildGlyphIndex } from "../backend/font_util/glyph_index";
async function main() {
const started = Date.now();
let built = 0;
let failed = 0;
for (const dir of fontDirs) {
let entries: { name: string; isFile: () => boolean }[];
try {
entries = await readdir(dir);
} catch {
continue;
}
for (const entry of entries) {
if (!entry.isFile() || !/\.(ttf|otf)$/i.test(entry.name)) continue;
const fontPath = `${dir}/${entry.name}`;
try {
const ok = await buildGlyphIndex(fontPath);
if (ok) {
built++;
console.log(`[${built}] ${entry.name} ✓`);
} else {
failed++;
console.log(`[skip] ${entry.name} 无有效字形`);
}
} catch (err) {
failed++;
console.error(`[fail] ${entry.name}:`, err instanceof Error ? err.message : err);
}
}
}
console.log(`完成:构建 ${built},失败 ${failed},耗时 ${((Date.now() - started) / 1000).toFixed(1)}s`);
}
main();