UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

94 lines (93 loc) • 2.78 kB
/** * Performance measurement and memory management utilities * Part of Sub-phase 3.3.1-3.3.2 optimization efforts */ import type { PerformanceMetrics } from "../types/index.js"; /** * Performance measurement utility for tracking operations */ export declare class PerformanceTracker { private metrics; /** * Start tracking performance for an operation */ start(operationName: string): void; /** * End tracking and calculate metrics */ end(operationName: string): PerformanceMetrics | null; /** * Get metrics for an operation */ getMetrics(operationName: string): PerformanceMetrics | null; /** * Clear all metrics */ clear(): void; /** * Format metrics for display */ formatMetrics(operationName: string): string; } /** * Global performance tracker instance */ export declare const globalTracker: PerformanceTracker; /** * Memory management utilities */ export declare class MemoryManager { /** * Force garbage collection if available */ static forceGC(): boolean; /** * Get current memory usage in MB */ static getMemoryUsageMB(): { rss: number; heapTotal: number; heapUsed: number; external: number; }; /** * Monitor memory usage and warn if it exceeds threshold */ static monitorMemory(threshold?: number): boolean; /** * Clean up and optimize memory usage. * Attempts to force garbage collection if available. * * @returns {object|null} Memory usage statistics if cleanup was performed, or null if not possible. * - If manual garbage collection is not available (i.e., Node.js not run with --expose-gc), * no cleanup is performed and null is returned. * - Clearing the require cache is not attempted due to potential side effects. */ static cleanup(): { beforeMB: number; afterMB: number; freedMB: number; } | null; } /** * Decorator for tracking performance of async functions */ export declare function trackPerformance(operationName: string): <T extends (...args: unknown[]) => Promise<unknown>>(_target: unknown, _propertyName: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>; /** * Performance monitoring for CLI operations */ export declare class CLIPerformanceMonitor { private static instance; private enabled; static getInstance(): CLIPerformanceMonitor; enable(): void; disable(): void; /** * Monitor a CLI operation */ monitorOperation<T>(operationName: string, operation: () => Promise<T>): Promise<T>; } /** * Export singleton monitor for easy access */ export declare const cliMonitor: CLIPerformanceMonitor;