






















@@ -22,6 +22,7 @@ export type ControlUiRefreshRun = {
2222const EVENT_LOG_LIMIT = 250;
2323const SLOW_RPC_MS = 1_000;
2424const RESPONSIVENESS_ENTRY_MS = 50;
25+const RESPONSIVENESS_EVENT_LOG_LIMIT = 50;
25262627type ControlUiResponsivenessObserver = {
2728disconnect: () => void;
@@ -86,11 +87,19 @@ export function recordControlUiPerformanceEvent(
8687host: ControlUiPerformanceHost,
8788event: string,
8889payload: Record<string, unknown>,
89-opts?: { warn?: boolean; console?: boolean },
90+opts?: { warn?: boolean; console?: boolean; maxBufferedEventsForType?: number },
9091) {
9192const entry: EventLogEntry = { ts: Date.now(), event, payload };
9293if (Array.isArray(host.eventLogBuffer)) {
93-host.eventLogBuffer = [entry, ...host.eventLogBuffer].slice(0, EVENT_LOG_LIMIT);
94+const existingBuffer =
95+typeof opts?.maxBufferedEventsForType === "number"
96+ ? keepLatestBufferedEventsForType(
97+host.eventLogBuffer,
98+event,
99+Math.max(0, opts.maxBufferedEventsForType - 1),
100+)
101+ : host.eventLogBuffer;
102+host.eventLogBuffer = [entry, ...existingBuffer].slice(0, EVENT_LOG_LIMIT);
94103if (host.tab === "debug" || host.tab === "overview") {
95104host.eventLog = host.eventLogBuffer;
96105}
@@ -101,6 +110,26 @@ export function recordControlUiPerformanceEvent(
101110logPerformanceEvent(event, payload, opts?.warn === true);
102111}
103112113+function keepLatestBufferedEventsForType(
114+entries: unknown[],
115+event: string,
116+maxExistingForType: number,
117+): unknown[] {
118+let keptForType = 0;
119+return entries.filter((entry) => {
120+if (
121+!entry ||
122+typeof entry !== "object" ||
123+!("event" in entry) ||
124+(entry as { event?: unknown }).event !== event
125+) {
126+return true;
127+}
128+keptForType += 1;
129+return keptForType <= maxExistingForType;
130+});
131+}
132+104133export function scheduleControlUiTabVisibleTiming(
105134host: ControlUiPerformanceHost,
106135previousTab: Tab,
@@ -256,7 +285,7 @@ function recordResponsivenessEntry(
256285scriptCount: Array.isArray(entry.scripts) ? entry.scripts.length : undefined,
257286topScript: getTopLongAnimationFrameScript(entry.scripts),
258287},
259-{ warn: true },
288+{ warn: true, maxBufferedEventsForType: RESPONSIVENESS_EVENT_LOG_LIMIT },
260289);
261290}
262291此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。