Skip to content

Commit

Permalink
Tweak typings
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Sep 16, 2024
1 parent 9e480d4 commit bc868d9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/prepare/jora-methods-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const safeRequestIdleCallback = typeof requestIdleCallback === 'function'
? requestIdleCallback
: (fn: () => void) => setTimeout(fn, 100);

export function trackExecutionTime(methods: Record<string, () => unknown>, trackMethodNames: string[]) {
let scheduleTimingsLoggingBuffer = [[]];
let scheduleTimingsLoggingFrameTimer = null;
let scheduleTimingsLoggingTimer = null;
export function trackExecutionTime<T extends Record<string,(...args: unknown[]) => unknown>>(methods: T, trackMethodNames: (keyof T & string)[]) {
let scheduleTimingsLoggingBuffer: [label: string, ...unknown[]][][] = [[]];
let scheduleTimingsLoggingFrameTimer: number | null = null;
let scheduleTimingsLoggingTimer: number | null = null;
let frameIdx = 0;

for (const methodName of trackMethodNames) {
Expand All @@ -17,7 +17,7 @@ export function trackExecutionTime(methods: Record<string, () => unknown>, track
try {
return fn.apply(this, args);
} finally {
scheduleTimingsLoggingBuffer.at(-1).push([`${methodName}() — ${Date.now() - startTime}ms`, args]);
scheduleTimingsLoggingBuffer.at(-1)?.push([`${methodName}() — ${Date.now() - startTime}ms`, args]);

if (scheduleTimingsLoggingFrameTimer === null) {
scheduleTimingsLoggingFrameTimer = requestAnimationFrame(() => {
Expand All @@ -30,13 +30,13 @@ export function trackExecutionTime(methods: Record<string, () => unknown>, track
scheduleTimingsLoggingTimer = safeRequestIdleCallback(() => {
const buffer = scheduleTimingsLoggingBuffer;

cancelAnimationFrame(scheduleTimingsLoggingFrameTimer);
cancelAnimationFrame(scheduleTimingsLoggingFrameTimer as number);

scheduleTimingsLoggingFrameTimer = null;
scheduleTimingsLoggingTimer = null;
scheduleTimingsLoggingBuffer = [[]];

if (buffer.at(-1).length === 0) {
if (buffer.at(-1)?.length === 0) {
buffer.pop();
}

Expand All @@ -52,6 +52,6 @@ export function trackExecutionTime(methods: Record<string, () => unknown>, track
});
}
}
};
} as T[typeof methodName];
}
}

0 comments on commit bc868d9

Please sign in to comment.