From 1da81eb0c05d049bf2ee333853e2b7a33b625ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=AE=E7=94=9F=EF=BC=88=E5=AD=90=E8=99=9A=EF=BC=89?= <2234839456@qq.com> Date: Fri, 24 Jul 2026 10:02:46 +0800 Subject: [PATCH] =?UTF-8?q?chore(gsub-subset):=20=E6=B8=85=E7=90=86=20prof?= =?UTF-8?q?iling=20=E6=AE=8B=E7=95=99=E7=9A=84=20=5F=5Fsp=20=E6=8F=92?= =?UTF-8?q?=E6=A1=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一轮 opt317 提交时误带入了 format1/format3 序列化路径上的 __sp 计时 插桩(globalThis 属性读取 + performance.now 调用)。热路径每个 type6 subtable 都执行,属无关生产代码。删除并移除无用的 perf_hooks import。 GSUB 字节输出零变化(cmp 一致),性能持平。 Co-Authored-By: Claude Opus 4.8 (1M context) --- backend/font_util/gsub-subset.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/backend/font_util/gsub-subset.ts b/backend/font_util/gsub-subset.ts index 149c766..50b2e54 100644 --- a/backend/font_util/gsub-subset.ts +++ b/backend/font_util/gsub-subset.ts @@ -22,7 +22,6 @@ */ import { OTWriter as Writer, OTReader as Reader, serializeScriptList, serializeFeatureList } from "./ot-bytes.js"; -import { performance } from "perf_hooks"; /** GSUB lookup 类型常量 */ const LT_SINGLE = 1; @@ -579,7 +578,6 @@ function serializeLigatureSubst( function readClassDefMap(r: Reader, off: number, origToNew: Map): Map { const result = new Map(); if (off === 0) return result; - const __f10 = (globalThis).__sp?performance.now():0; const format = r.u16(off); if (format === 1) { const startGid = r.u16(off + 2); @@ -649,7 +647,6 @@ function serializeChainedContextSubst( covCache: CoverageCache, gidLookup: GidLookup, ): boolean { - const __f10 = (globalThis).__sp?performance.now():0; const format = r.u16(off); if (format === 1) { /** coverage(gid) + 子规则数组,每规则含 backtrack/input/lookahead gid 序列 + SubstLookupRecord */ @@ -676,11 +673,10 @@ function serializeChainedContextSubst( } if (validRules.length > 0) entries.push({ firstGid: firstNew, rules: validRules }); } - if (entries.length === 0) { if((globalThis).__sp){const G=globalThis as any; G.__f1_fail_t=(G.__f1_fail_t||0)+performance.now()-__f10; G.__f1_fail_c=(G.__f1_fail_c||0)+1;} return false; } + if (entries.length === 0) return false; /** 按 firstGid 升序排序,使 coverage(emitCoverage 强制升序)与 SubRuleSet 数组保持下标配对 */ entries.sort((a, b) => a.firstGid - b.firstGid); writeChainFormat1(w, entries); - if((globalThis).__sp){const G=globalThis as any; G.__f1_ok_t=(G.__f1_ok_t||0)+performance.now()-__f10; G.__f1_ok_c=(G.__f1_ok_c||0)+1;} return true; } @@ -737,12 +733,10 @@ function serializeChainedContextSubst( } if (format === 3) { - const __f30 = (globalThis).__sp?performance.now():0; /** 显式 coverage 数组 + SubstLookupRecord */ const parsed = parseChainFormat3(r, off, covCache, gidLookup); - if (!parsed) { if((globalThis).__sp){const G=globalThis as any; G.__f3_fail_t=(G.__f3_fail_t||0)+performance.now()-__f30; G.__f3_fail_c=(G.__f3_fail_c||0)+1;} return false; } + if (!parsed) return false; writeChainFormat3(w, parsed); - if((globalThis).__sp){const G=globalThis as any; G.__f3_ok_t=(G.__f3_ok_t||0)+performance.now()-__f30; G.__f3_ok_c=(G.__f3_ok_c||0)+1;} return true; }