PerformanceManager

See source code
Table of contents

Extends EditorManager.

Manages performance event subscriptions for the editor. Available as editor.performance.

Listeners are lazy — internal editor hooks (frame, shape events) are only attached while at least one subscriber exists, so there is zero overhead when unused.

class PerformanceManager extends EditorManager {}

Example

const unsub = editor.performance.on("interaction-end", (event) => {
  console.log(
    `${event.name}: ${event.fps.toFixed(1)} fps, p95=${event.p95FrameTime.toFixed(1)}ms`,
  );
});

Constructor

Constructs a new instance of the EditorManager class

Parameters

NameDescription

editor

Editor;

Properties

disposables

readonly
protected readonly disposables: Set<() => void>;

editor

readonly
protected readonly editor: Editor;

Methods

addEditorEvent( )

Subscribe to an editor bus event and register the matching unsubscribe, so the listener is removed automatically on dispose(). Returns that unsubscribe, for passing to EditorManager.unregister to detach it before dispose().

protected addEditorEvent<E extends keyof TLEventMap>(
  event: E,
  fn: (...args: TLEventMap[E]) => void,
): () => void;

Parameters

NameDescription

event

E;

fn

(...args: TLEventMap[E]) => void;

Returns

() => void;

on( )

Subscribe to a performance event. Returns an unsubscribe function.

on<K extends keyof TLPerfEventMap>(
  event: K,
  fn: (...args: TLPerfEventMap[K]) => void,
): () => void;

Example

const unsub = editor.performance.on("interaction-end", (event) => {
  sendToAnalytics({
    name: event.name,
    fps: event.fps,
    p95: event.p95FrameTime,
  });
});
// later: unsub()

Parameters

NameDescription

event

K;

fn

(...args: TLPerfEventMap[K]) => void;

Returns

() => void;

once( )

Subscribe to a performance event once. The listener is removed after the first invocation. Returns an unsubscribe function for early removal.

once<K extends keyof TLPerfEventMap>(
  event: K,
  fn: (...args: TLPerfEventMap[K]) => void,
): () => void;

Parameters

NameDescription

event

K;

fn

(...args: TLPerfEventMap[K]) => void;

Returns

() => void;

register( )

Register a teardown function to run on dispose(). The universal way for a manager to make a resource "see itself out". Returns the same function for convenience.

protected register(dispose: () => void): () => void;

Parameters

NameDescription

dispose

() => void;

Returns

() => void;

unregister( )

Run a registered teardown now instead of at dispose(). A teardown that is no longer registered (already run by dispose(), or never registered) is skipped, so nothing is torn down twice.

protected unregister(dispose: () => void): void;

Parameters

NameDescription

dispose

() => void;

Returns

void;

Prev
PerformanceApiAdapter
Next
Point2d