A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
perf(editor): stop the play-mode Outliner re-committing on every inspect tick
yhhdb66a7670be9
diff --git a/desktop/src/engine/PlayInspect.ts b/desktop/src/engine/PlayInspect.tsindex 4b6a1f474..e48746355 100644--- a/desktop/src/engine/PlayInspect.ts+++ b/desktop/src/engine/PlayInspect.ts@@ -48,6 +48,10 @@ class PlayInspectImpl {subscribe = (fn: () => void): (() => void) => this.store.subscribe(fn);getSnapshot = (): PlayInspectState => this.store.getState();+ /** Narrow, identity-stable slices: a per-tick selected-entity refresh must+ * not re-render tree-only subscribers (the Outliner). */+ getTree = (): SceneData | null => this.store.getState().snapshot;+ getSelection = (): EntityId | null => this.store.getState().selection;select(selection: EntityId | null): void {this.store.setState({ ...this.store.getState(), selection });@@ -94,7 +98,17 @@ class PlayInspectImpl {// memoized tree build is skipped between samples; only the selected entity (the// Details payload) refreshes each tick.const sameTree = cur.snapshot != null && treeSig(cur.snapshot) === treeSig(res.tree);- this.store.setState({ snapshot: sameTree ? cur.snapshot : res.tree, selectedEntity: res.selected, selection: cur.selection });+ const sameSelected = cur.selectedEntity === res.selected+ || (cur.selectedEntity != null && res.selected != null+ && JSON.stringify(cur.selectedEntity) === JSON.stringify(res.selected));+ // Nothing changed (idle play, no selection): don't notify — a store bump+ // here re-committed every subscriber on each 16ms tick for no reason.+ if (sameTree && sameSelected) return;+ this.store.setState({+ snapshot: sameTree ? cur.snapshot : res.tree,+ selectedEntity: sameSelected ? cur.selectedEntity : res.selected,+ selection: cur.selection,+ });}}diff --git a/desktop/src/panels/Outliner.tsx b/desktop/src/panels/Outliner.tsxindex d1faf0342..ec1503d8a 100644--- a/desktop/src/panels/Outliner.tsx+++ b/desktop/src/panels/Outliner.tsx@@ -38,7 +38,10 @@ const entityIds = (items: OutlinerItem[]): EntityId[] =>// One row of the live "Game" tree: a read-only, always-expanded// view of the running realm, sharing the editor's virtualization. No folders.function GameTree() {- const { snapshot, selection } = useSyncExternalStore(PlayInspect.subscribe, PlayInspect.getSnapshot);+ // Narrow slices: identity-stable between ticks, so React bails out of the+ // re-render while only the selected entity's live values are refreshing.+ const snapshot = useSyncExternalStore(PlayInspect.subscribe, PlayInspect.getTree);+ const selection = useSyncExternalStore(PlayInspect.subscribe, PlayInspect.getSelection);const items = useMemo(() => buildOutlinerItems(snapshot, { expanded: NO_EXPANSION, expandAll: true }), [snapshot]);if (items.length === 0) {