MCPcopy Create free account
hub / github.com/GCWing/BitFun / markPhaseAfterAnimationFrames

Function markPhaseAfterAnimationFrames

src/web-ui/src/shared/utils/startupTrace.ts:603–640  ·  view source on GitHub ↗
(
  trace: StartupTrace,
  phase: string,
  data?: TraceData,
  options: DeferredAnimationFrameTraceOptions = {}
)

Source from the content-addressed store, hash-verified

601}
602
603export function markPhaseAfterAnimationFrames(
604 trace: StartupTrace,
605 phase: string,
606 data?: TraceData,
607 options: DeferredAnimationFrameTraceOptions = {}
608): void {
609 const frameCount = Math.max(1, Math.floor(options.frameCount ?? 2));
610 const now = options.now ?? (() => globalThis.performance?.now?.() ?? Date.now());
611 const requestFrame = options.requestAnimationFrame ?? globalThis.requestAnimationFrame?.bind(globalThis);
612 const startedAt = now();
613
614 if (!requestFrame) {
615 trace.markPhase(phase, {
616 ...(data ?? {}),
617 frameCount: 0,
618 durationMs: 0,
619 });
620 return;
621 }
622
623 let remainingFrames = frameCount;
624 const scheduleNextFrame = () => {
625 requestFrame(() => {
626 remainingFrames -= 1;
627 if (remainingFrames <= 0) {
628 trace.markPhase(phase, {
629 ...(data ?? {}),
630 frameCount,
631 durationMs: roundDurationMs(now() - startedAt),
632 });
633 return;
634 }
635 scheduleNextFrame();
636 });
637 };
638
639 scheduleNextFrame();
640}

Callers 3

loadSessionHistoryMethod · 0.90

Calls 3

bindMethod · 0.80
markPhaseMethod · 0.80
scheduleNextFrameFunction · 0.70

Tested by

no test coverage detected