mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-31 17:19:56 +08:00
25227a09f7
fix #14433 #### PR Dependency Tree * **PR #14442** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Level-of-detail thumbnails for large images. * Adaptive pacing for snapping, distribution and other alignment work. * RAF coalescer utility to batch high-frequency updates. * Operation timing utility to measure synchronous work. * **Improvements** * Batch group/ungroup reparenting that preserves element order and selection. * Coalesced panning and drag updates to reduce jitter. * Connector/group indexing for more reliable updates, deletions and sync. * Throttled viewport refresh behavior. * **Documentation** * Docs added for RAF coalescer and measureOperation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
32 lines
843 B
TypeScript
32 lines
843 B
TypeScript
let opMeasureSeq = 0;
|
|
|
|
/**
|
|
* Measure operation cost via Performance API when available.
|
|
*
|
|
* Marks are always cleared, while measure entries are intentionally retained
|
|
* so callers can inspect them from Performance tools.
|
|
*/
|
|
export const measureOperation = <T>(name: string, fn: () => T): T => {
|
|
if (
|
|
typeof performance === 'undefined' ||
|
|
typeof performance.mark !== 'function' ||
|
|
typeof performance.measure !== 'function'
|
|
) {
|
|
return fn();
|
|
}
|
|
|
|
const operationId = opMeasureSeq++;
|
|
const startMark = `${name}:${operationId}:start`;
|
|
const endMark = `${name}:${operationId}:end`;
|
|
performance.mark(startMark);
|
|
|
|
try {
|
|
return fn();
|
|
} finally {
|
|
performance.mark(endMark);
|
|
performance.measure(name, startMark, endMark);
|
|
performance.clearMarks(startMark);
|
|
performance.clearMarks(endMark);
|
|
}
|
|
};
|