perf(glyf): simple 字形 fast-path glyfObj 改对象字面量消除隐藏类迁移

glyf.read 的 simple 字形快路径原用 `var glyfObj = {}` 后逐个赋值 9 个属性
(xMin/yMin/xMax/yMax/_origBuf/_origOff/_origLen/_numContours/_totalPoints),
每个字形产生 9 次隐藏类迁移。改为对象字面量一次性创建所有属性,V8 分配稳定隐藏类
(无迁移),且 numberOfContours>0 / =0 统一形状(_numContours 直接用值,
_totalPoints 用三元表达式)。

千字文(129 simple 字形)Font.create best-of p50 约 -3%(多轮 0.1527→0.1479)。
5 字体 woff2 sha 逐字节一致,SSIM 全部不变(仅对象创建方式变化,属性集完全相同)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
崮生(子虚) 2026-07-24 20:44:55 +08:00
parent c6316378f2
commit eb3ed06d41

View File

@ -100,22 +100,17 @@ var _default = exports.default = _table.default.create('glyf', [], {
* 优化313: 不再分配 endPtsOfContours 数组_totalPoints 只需最后一个 endPt
* 优化314: 原始字节引用展平到 glyfObj_origBuf/_origOff/_origLen
* 省掉每个 simple 字形的 _origGlyfRef 子对象分配 */
var glyfObj = {};
glyfObj.xMin = view.getInt16(vOff + 2, false);
glyfObj.yMin = view.getInt16(vOff + 4, false);
glyfObj.xMax = view.getInt16(vOff + 6, false);
glyfObj.yMax = view.getInt16(vOff + 8, false);
glyfObj._origBuf = fullBuf;
glyfObj._origOff = fullBufOff + gStart;
glyfObj._origLen = gEnd - gStart;
if (numberOfContours > 0) {
glyfObj._numContours = numberOfContours;
/** 最后一个 endPt 在 vOff + 10 + (numContours-1)*2+1 即总点数 */
glyfObj._totalPoints = view.getUint16(vOff + 10 + (numberOfContours - 1) * 2, false) + 1;
} else {
glyfObj._numContours = 0;
glyfObj._totalPoints = 0;
}
var glyfObj = {
xMin: view.getInt16(vOff + 2, false),
yMin: view.getInt16(vOff + 4, false),
xMax: view.getInt16(vOff + 6, false),
yMax: view.getInt16(vOff + 8, false),
_origBuf: fullBuf,
_origOff: fullBufOff + gStart,
_origLen: gEnd - gStart,
_numContours: numberOfContours,
_totalPoints: numberOfContours > 0 ? view.getUint16(vOff + 10 + (numberOfContours - 1) * 2, false) + 1 : 0,
};
glyphs[index] = glyfObj;
} else {
/* compound 字形:完整 parsecomponent glyphIndex 后续要重映射) */