@lifeart/gxt
Version:
<img align="right" width="95" height="95" alt="Philosopher’s stone, logo of PostCSS" src="./public/logo.png">
76 lines (75 loc) • 2.2 kB
TypeScript
/**
* Runtime configuration for GXT memory pools.
* These settings control pool sizes and adaptive growth behavior.
*/
export interface PoolConfig {
/** Initial pool size */
initial: number;
/** Maximum pool size (hard cap) */
max: number;
/** Growth factor when pool is exhausted (e.g., 1.5 = 50% growth) */
growthFactor: number;
/** Shrink threshold - shrink when usage drops below this ratio of current size */
shrinkThreshold: number;
/** Minimum size to shrink to (won't go below initial) */
minSize: number;
}
export interface GXTConfig {
/** Pool for ops arrays in reactive system */
opsArrayPool: PoolConfig;
/** Pool for destructor arrays */
destructorArrayPool: PoolConfig;
/** Pool for component IDs */
idPool: PoolConfig;
}
/** Partial config type for configureGXT - allows partial pool configs */
export type GXTConfigInput = {
opsArrayPool?: Partial<PoolConfig>;
destructorArrayPool?: Partial<PoolConfig>;
idPool?: Partial<PoolConfig>;
};
export declare const config: GXTConfig;
/**
* Configure GXT runtime settings.
* Call this before rendering to customize pool behavior.
*/
export declare function configureGXT(userConfig: GXTConfigInput): void;
/**
* Adaptive pool manager that handles growth and shrinking.
*/
export declare class AdaptivePool<T> {
private pool;
private currentMaxSize;
private config;
private createFn;
private resetFn;
private totalAllocated;
private highWaterMark;
constructor(config: PoolConfig, createFn: () => T, resetFn?: (item: T) => void);
/**
* Get an item from the pool or create a new one.
*/
acquire(): T;
/**
* Return an item to the pool.
*/
release(item: T): void;
/**
* Shrink the pool if it's significantly underutilized.
* Call this periodically (e.g., on idle) to reclaim memory.
*/
maybeShrink(): void;
/**
* Get current pool statistics.
*/
getStats(): {
poolSize: number;
currentMaxSize: number;
totalAllocated: number;
highWaterMark: number;
};
/**
* Clear the pool entirely.
*/
clear(): void;
}