UNPKG

@gulibs/vgrove-ui

Version:

VGrove UI component library built with HeroUI and React

150 lines 4.18 kB
/** * 性能优化相关工具 */ export declare class PerformanceCache<K, V> { private cache; private accessTimes; private maxSize; constructor(maxSize?: number); get(key: K): V | undefined; set(key: K, value: V): void; has(key: K): boolean; delete(key: K): boolean; clear(): void; size(): number; private evictLRU; } export declare class PerformanceTracker { private timers; private counters; startTimer(name: string): void; endTimer(name: string): number; increment(name: string): void; getCounter(name: string): number; reset(): void; getStats(): Record<string, any>; } /** * 批处理器 - 用于批量处理数据,避免一次性处理过多数据造成阻塞 */ export declare class BatchProcessor { private batchSize; private delay; constructor(batchSize?: number, delay?: number); /** * 批量处理数据 * @param items 待处理的数据数组 * @param processor 处理函数 * @returns 处理结果数组 */ processBatch<T, R>(items: T[], processor: (item: T) => Promise<R>): Promise<R[]>; /** * 批量处理数据(同步版本) * @param items 待处理的数据数组 * @param processor 处理函数 * @param onProgress 进度回调 * @returns 处理结果数组 */ processBatchSync<T, R>(items: T[], processor: (item: T) => R, onProgress?: (progress: number) => void): R[]; } /** * 防抖器 - 用于防抖操作,避免频繁触发 */ export declare class Debouncer { private timers; /** * 防抖执行函数 * @param key 唯一标识符 * @param fn 要执行的函数 * @param delay 延迟时间(毫秒) */ debounce(key: string, fn: () => void, delay?: number): void; /** * 取消指定的防抖 * @param key 唯一标识符 */ cancel(key: string): void; /** * 取消所有防抖 */ cancelAll(): void; /** * 获取当前活跃的防抖数量 */ size(): number; } /** * 内存优化器 - 用于管理内存清理任务 */ export declare class MemoryOptimizer { private static instance; private cleanupTasks; private intervalId; private constructor(); static getInstance(): MemoryOptimizer; /** * 添加清理任务 * @param id 任务ID * @param task 清理任务函数 * @param priority 优先级(数字越大优先级越高) */ addCleanupTask(id: string, task: () => void, priority?: number): void; /** * 移除清理任务 * @param id 任务ID */ removeCleanupTask(id: string): void; /** * 开始周期性清理 * @param intervalMs 清理间隔(毫秒) */ startPeriodicCleanup(intervalMs?: number): void; /** * 停止周期性清理 */ stopPeriodicCleanup(): void; /** * 运行所有清理任务 */ runCleanup(): void; /** * 获取清理任务信息 */ getCleanupInfo(): { taskCount: number; isRunning: boolean; tasks: Array<{ id: string; priority: number; }>; }; /** * 释放资源 */ dispose(): void; } /** * 异步性能测量工具 * @param name 性能测量名称 * @param fn 要测量的异步函数 * @returns 包含执行结果和性能信息的对象 */ export declare function measureAsync<T>(name: string, fn: () => Promise<T>): Promise<T & { _performance: { name: string; duration: number; timestamp: number; }; }>; /** * 创建一个带有性能监控的函数包装器 * @param name 性能测量名称 * @param fn 要包装的函数 * @returns 包装后的函数 */ export declare function withPerformanceMonitoring<Args extends any[], Return>(name: string, fn: (...args: Args) => Return): (...args: Args) => Return; export declare const globalPerformanceTracker: PerformanceTracker; export declare const globalMemoryOptimizer: MemoryOptimizer; export declare const globalBatchProcessor: BatchProcessor; export declare const globalDebouncer: Debouncer; //# sourceMappingURL=performance.d.ts.map