circuit-bricks
Version:
A modular, Lego-style SVG circuit component system for React (ALPHA - Not for production use)
151 lines • 4.02 kB
TypeScript
/**
* Performance Monitoring Utilities
*
* Utilities for monitoring and optimizing rendering performance in Circuit-Bricks.
* These tools help track component render times, memory usage, and provide
* insights for performance optimization.
*/
import React from 'react';
/**
* Performance metrics interface
*/
export interface PerformanceMetrics {
renderTime: number;
componentCount: number;
wireCount: number;
memoryUsage?: number;
timestamp: number;
}
/**
* Performance monitoring configuration
*/
export interface PerformanceConfig {
enabled: boolean;
sampleRate: number;
maxSamples: number;
logToConsole: boolean;
trackMemory: boolean;
}
/**
* Performance monitor class
*/
declare class PerformanceMonitor {
private config;
private samples;
private observers;
constructor(config?: Partial<PerformanceConfig>);
/**
* Update configuration
*/
updateConfig(config: Partial<PerformanceConfig>): void;
/**
* Check if monitoring should occur for this render
*/
shouldMeasure(): boolean;
/**
* Start measuring a render
*/
startMeasure(label?: string): () => PerformanceMetrics | null;
/**
* Get memory usage (if available)
*/
private getMemoryUsage;
/**
* Add a performance sample
*/
private addSample;
/**
* Subscribe to performance updates
*/
subscribe(observer: (metrics: PerformanceMetrics) => void): () => void;
/**
* Get performance statistics
*/
getStats(): {
sampleCount: number;
renderTime: {
avg: number;
min: number;
max: number;
p95: number;
p99: number;
};
componentCount: {
avg: number;
min: number;
max: number;
};
wireCount: {
avg: number;
min: number;
max: number;
};
} | null;
/**
* Calculate percentile
*/
private percentile;
/**
* Clear all samples
*/
clearSamples(): void;
/**
* Export samples for analysis
*/
exportSamples(): PerformanceMetrics[];
}
declare const globalMonitor: PerformanceMonitor;
/**
* Hook for measuring component render performance
*/
export declare const useRenderPerformance: (componentName: string, componentCount?: number, wireCount?: number) => void;
/**
* Hook for subscribing to performance metrics
*/
export declare const usePerformanceMetrics: () => {
latestMetrics: PerformanceMetrics | null;
stats: {
sampleCount: number;
renderTime: {
avg: number;
min: number;
max: number;
p95: number;
p99: number;
};
componentCount: {
avg: number;
min: number;
max: number;
};
wireCount: {
avg: number;
min: number;
max: number;
};
} | null;
clearMetrics: () => void;
exportMetrics: () => PerformanceMetrics[];
};
/**
* Configure global performance monitoring
*/
export declare const configurePerformanceMonitoring: (config: Partial<PerformanceConfig>) => void;
/**
* Performance-aware component wrapper
*/
export declare const withPerformanceMonitoring: <P extends object>(Component: React.ComponentType<P>, componentName: string) => React.MemoExoticComponent<(props: P) => import("react/jsx-runtime").JSX.Element>;
/**
* Debounced function utility for performance optimization
*/
export declare const useDebounce: <T extends (...args: any[]) => any>(func: T, delay: number) => T;
/**
* Throttled function utility for performance optimization
*/
export declare const useThrottle: <T extends (...args: any[]) => any>(func: T, delay: number) => T;
/**
* Frame rate monitor
*/
export declare const useFrameRate: () => number;
export { globalMonitor as performanceMonitor };
//# sourceMappingURL=performanceUtils.d.ts.map