docs(tests): explain renderer timing and migration probes

This commit is contained in:
2026-11-12 18:25:52 +08:00
parent 357c92d749
commit f0c7c83b24
3 changed files with 7 additions and 1 deletions
+3
View File
@@ -107,6 +107,7 @@ export async function measureRenderer({call,evaluate,documents,calls=[],root,par
// 捕获复制开始前的原文,用来证明并发输入不进入已经捕获的副本。
const sourceText=documents.get(root).elements.get('perf-0').data.text;
// 页面脚本以 rAF 采样新 DOM、进度完成、节点峰值、帧间隔,并在支持时观察 longtask;tick 反复采样,read 汇总,stop 取消并断开 observer。
// maxMountedNodes 仅是采样帧看到的最大值;prepareMs 是从采样开始到准备提示消失的时间,未见提示时为 null,不是准备阶段独立耗时。
await evaluate(`(()=>{
const originals=new Set(['perf-source','perf-frame',...Array.from({length:${count}},(_,i)=>'perf-'+i)]),start=performance.now(),tasks=[],gaps=[];
let raf,last=start,sawPreparing=false,firstDOM=null,firstFrame=null,localComplete=null,localCompleteFrame=null,prepared=null,maxNodes=0;
@@ -125,6 +126,8 @@ export async function measureRenderer({call,evaluate,documents,calls=[],root,par
await evaluate('new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)))');
// 完成进度与已同步后再等两帧,要求 renderer 测量出现合批;统计批量大小而非只计渲染总数。
const internalsBatches=await evaluate('window.__fixtureInternalsBatches??[]');assert.ok(internalsBatches.some(size=>size>1),'mounted nodes did not share a renderer measurement batch');
// 原文档有 count 张卡片、source、frame 和入边;副本增加 count 张卡片、frame′ 和新入边,因此总元素为 2*count+5。
// 进度 count+3 还计入新子 canvas,canvas 记录不属于 document.elements,不能拿进度数直接推元素总量。
// 停止页面采样并验证服务元素数、复制 canvas 和上级连线。firstPresentedFrame 是检测新 DOM 后的下一次 rAF 近似值,不是 compositor 上屏证明。
const measurements=await evaluate('window.__canvasPerformance.stop()'),document=documents.get(root),copiedCanvas=[...document.canvases.values()].find(canvas=>canvas.parent&&canvas.id!==partition);
assert.equal(document.elements.size,2*count+5);assert.ok(copiedCanvas);assert.ok([...document.elements.values()].some(element=>element.structure==='connection'&&element.source.elementId==='perf-source'&&element.target.elementId===copiedCanvas.parent.entryElementId));assert.ok(document.elements.has('perf-incoming'));assert.ok(measurements.firstPresentedFrameMs!==null&&measurements.localCompleteFrameMs!==null);if(count>=100)assert.ok(measurements.nodeCount<target,'offscreen DOM was not culled');assert.ok(await evaluate(`document.querySelector('[aria-label="画布导入"]').textContent.includes('${count+3} 项')`),'copy progress did not include all source records');