refactor(app): centralize perf diagnostics and activity coalescing

This commit is contained in:
Mohamed Boudra
2026-02-22 11:52:08 +07:00
parent d7e2ab4437
commit d6b7c2ed2d
24 changed files with 1119 additions and 81 deletions
@@ -0,0 +1,26 @@
import type { ActivityFlushHandle } from "./types";
const DEFAULT_ACTIVITY_FLUSH_INTERVAL_MS = 16;
export function scheduleAgentLastActivityFlush(
callback: () => void,
fallbackIntervalMs = DEFAULT_ACTIVITY_FLUSH_INTERVAL_MS
): ActivityFlushHandle {
if (typeof requestAnimationFrame === "function") {
const handle = requestAnimationFrame(callback);
return {
cancel: () => {
if (typeof cancelAnimationFrame === "function") {
cancelAnimationFrame(handle);
}
},
};
}
const handle = setTimeout(callback, fallbackIntervalMs);
return {
cancel: () => {
clearTimeout(handle);
},
};
}