perf(woff2): transformGlyfAndLoca simple glyph 跳过 bbox 读取

原每个 glyph 入口都读 numberOfContours + xMin/yMin/xMax/yMax 共 5 次 readI16,
但 simple glyph 的 bbox 由解码端从轮廓点重建(优化314,bboxBitmap 位恒为 0,
不写入 bboxStream),xMin/yMin/xMax/yMax 读取纯属浪费。仅复合 glyph 需显式存
bbox(raw 组件数据剥离 glyph 头,解码端无法重建)。

将 bbox 4 次 readI16 移入复合 glyph 分支(numberOfContours<0),simple glyph
路径只读 numberOfContours 一次。CJK 字体几乎全 simple,每字省 4 次 readI16。

7 产物 A/B 全 IDENTICAL。性能 best-of min N=4000:
篆体 -4.6%、思源8字 -2.3%、FiraCode -1.7%、令东8字 -1.4%、千字文 -1.1%。
基准测试全 SSIM 通过。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
崮生(子虚) 2026-07-25 03:59:53 +08:00
parent 32afa17b5c
commit e1190eeb82

View File

@ -254,13 +254,15 @@ function transformGlyfAndLoca(glyfData, locaData, indexFormat, numGlyphs) {
}
const numberOfContours = readI16(glyfData, glyphStart);
const xMin = readI16(glyfData, glyphStart + 2);
const yMin = readI16(glyfData, glyphStart + 4);
const xMax = readI16(glyfData, glyphStart + 6);
const yMax = readI16(glyfData, glyphStart + 8);
if (numberOfContours < 0) {
/* 复合 glyph */
/* glyphbbox bboxStreamraw glyph
* 故仅复合 glyph 读取 xMin/yMin/xMax/yMaxsimple glyph bbox 由解码端从轮廓点重建
* 优化314bboxBitmap 位恒为 0读取纯属浪费移到复合分支内避免每 simple glyph 4 readI16 */
const xMin = readI16(glyfData, glyphStart + 2);
const yMin = readI16(glyfData, glyphStart + 4);
const xMax = readI16(glyfData, glyphStart + 6);
const yMax = readI16(glyfData, glyphStart + 8);
let compOff = glyphStart + 10;
let haveInstructions = false;
let instrLength = 0;