BaseEngineRegistry is a central registry for tracking all BaseEngine instances.

It provides:

  • Registration and tracking of engine singletons
  • Memory usage estimation across all engines
  • Cross-engine data sharing coordination
  • Bulk operations (refresh all, invalidate all)

Example

// Register an engine (typically done automatically by BaseEngine)
BaseEngineRegistry.Instance.RegisterEngine(MyEngine.Instance);

// Get memory stats
const stats = BaseEngineRegistry.Instance.GetMemoryStats();
console.log(`Total engines: ${stats.totalEngines}`);
console.log(`Total memory: ${(stats.totalEstimatedMemoryBytes / 1024 / 1024).toFixed(2)} MB`);

Hierarchy (view full)

Constructors

Properties

_engines: Map<string, EngineRegistrationInfo> = ...
_entityLoadTracking: Map<string, Set<string>> = ...

Tracks which engines have loaded which entities. Key: entity name, Value: Set of engine class names

_entitySizeCache: Map<string, number> = ...

Cache of estimated bytes per row for each entity type. This avoids re-sampling the same entity type multiple times during a session.

_recordedEngineInstances: WeakSet<object> = ...

Tracks which engine instances have already recorded their entity loads. Uses WeakSet so engine instances can be garbage collected when no longer in use. This prevents false positive warnings when a subclass and base class share the same singleton.

DEFAULT_BYTES_PER_ROW: 500 = 500

Default bytes per row when we can't sample (fallback)

Accessors

  • get GlobalKey(): string
  • Returns string

Methods

  • Estimate the size of an array in bytes by sampling the first row. Uses a cache to avoid re-sampling the same entity type multiple times.

    Parameters

    • arr: unknown[]

    Returns number

  • Get a registered engine by class name

    Type Parameters

    • T

    Parameters

    • className: string

      The class name of the engine

    Returns T

    The engine instance or null if not found

  • Gets a list of engines that have loaded a specific entity.

    Parameters

    • entityName: string

      The name of the entity

    Returns string[]

    Array of engine class names that have loaded this entity

  • Returns the entity load tracking data as a Map suitable for TelemetryAnalyzerContext. Key: entity name, Value: array of engine class names that have loaded this entity.

    Returns Map<string, string[]>

  • The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.

    Returns typeof globalThis

  • Gets all entities that have been loaded by multiple engines.

    Returns Map<string, string[]>

    Map of entity name to array of engine class names

  • Records that an engine has loaded a specific entity. If another engine has already loaded this entity, a warning is queued.

    Parameters

    • engineClassName: string

      The class name of the engine loading the entity

    • entityName: string

      The name of the entity being loaded

    Returns void

  • Records that an engine has loaded multiple entities. Convenience method for batch recording. Uses instance identity to prevent false positives when a subclass and base class share the same singleton (e.g., AIEngine extends AIEngineBase).

    Parameters

    • engine: object

      The engine instance that loaded the entities

    • entityNames: string[]

      Array of entity names being loaded

    Returns void

  • Register an engine instance with the registry. This is typically called automatically by BaseEngine during Config().

    Parameters

    • engine: unknown

      The engine instance to register

    • Optional className: string

      Optional class name override (uses constructor name by default)

    Returns void

  • Sample a single item to estimate its size in bytes. For BaseEntity objects, uses GetAll() to get plain field values.

    Parameters

    • item: unknown

    Returns number

  • Returns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.

    Type Parameters

    Parameters

    • this: (new () => T)
        • new (): T
        • Returns T

    • Optional className: string

    Returns T