mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 23:02:27 +08:00
优化310 快路径下 endPtsOfContours 数组仅用于算 _totalPoints(供 maxPoints metrics), 下游 optimizettf 快路径分支、sizeof/write 原始字节拷贝均不消费它。 直接读最后一个 endPt(vOff+10+(numContours-1)*2)算 _totalPoints, 省掉每个 simple 字形的 Array 分配 + numContours 次 getUint16 循环。 千字文 ttf 0.252→0.246ms,ttf 字节输出 cmp 完全一致,SSIM 全部不变。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
19 lines
1.1 KiB
TypeScript
19 lines
1.1 KiB
TypeScript
import { fontSubset } from './backend/font_util/font.js';
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
import { Session } from 'inspector';
|
|
const buf = readFileSync('font/令东齐伋复刻体.ttf');
|
|
const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
const text = '天地玄黄宇宙洪荒日月盈昃辰宿列张寒来暑往秋收冬藏闰余成岁律吕调阳云腾致雨露结为霜金生丽水玉出昆冈剑号巨阙珠称夜光果珍李柰菜重芥姜海咸河淡鳞潜羽翔';
|
|
const opt = {sourceType:'ttf' as const, outType:'woff2' as const};
|
|
(async()=>{
|
|
for(let i=0;i<50;i++) fontSubset(ab, text, opt);
|
|
const s = new Session();
|
|
s.connect();
|
|
await new Promise<void>(r=>s.post('Profiler.enable',()=>r()));
|
|
await new Promise<void>(r=>s.post('Profiler.start',()=>r()));
|
|
for(let i=0;i<2000;i++) fontSubset(ab, text, opt);
|
|
const prof:any = await new Promise(r=>s.post('Profiler.stop',(_,v)=>r(v)));
|
|
writeFileSync('/tmp/prof.json', JSON.stringify(prof));
|
|
console.log('profile written, samples=', prof.profile.samples.length);
|
|
})();
|