perf: trim session IPC hot paths and fix clear-effects idle render
Skip full project broadcast on graph/NPC position commits, send session.stateChanged only to consumer windows, and force one Pixi render before stopping the idle ticker so Clear effects actually clears the canvas. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+5
-5
@@ -54,6 +54,7 @@ import {
|
||||
closeMaterialsWindow,
|
||||
closeNpcsEditorWindow,
|
||||
closeNpcsWindow,
|
||||
sendToAppWindows,
|
||||
togglePresentationFullscreen,
|
||||
waitForEditorWindowReady,
|
||||
} from './windows/createWindows';
|
||||
@@ -229,9 +230,8 @@ function emitSessionState(): void {
|
||||
project,
|
||||
currentSceneId: project?.currentSceneId ?? null,
|
||||
};
|
||||
for (const win of BrowserWindow.getAllWindows()) {
|
||||
win.webContents.send(ipcChannels.session.stateChanged, { state });
|
||||
}
|
||||
// Не шлём полный project в editor/splash — редактор обновляется через invoke-ответы.
|
||||
sendToAppWindows(ipcChannels.session.stateChanged, { state });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,8 +676,8 @@ async function main() {
|
||||
},
|
||||
);
|
||||
registerHandler(ipcChannels.project.updateNpcPosition, async ({ npcId, x, y }) => {
|
||||
// Layout-only: Presentation/Control не читают npc.x/y; UI коммитит локально из ответа invoke.
|
||||
const project = await projectStore.updateNpcPosition(npcId, x, y);
|
||||
emitSessionState();
|
||||
return { project };
|
||||
});
|
||||
registerHandler(ipcChannels.project.deleteNpc, async ({ npcId }) => {
|
||||
@@ -811,8 +811,8 @@ async function main() {
|
||||
return { project };
|
||||
});
|
||||
registerHandler(ipcChannels.project.updateSceneGraphNodePosition, async ({ nodeId, x, y }) => {
|
||||
// Layout-only: граф сцен живёт в editor (optimistic + invoke); session broadcast не нужен.
|
||||
const project = await projectStore.updateSceneGraphNodePosition(nodeId, x, y);
|
||||
emitSessionState();
|
||||
return { project };
|
||||
});
|
||||
registerHandler(ipcChannels.project.addSceneGraphNode, async ({ sceneId, x, y }) => {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
/**
|
||||
* Фаза 6 (срез): layout-only мутации не должны слать полный Project во все окна.
|
||||
* Редактор НПС применяет позицию из ответа invoke локально.
|
||||
*/
|
||||
void test('session IPC: нет emitSessionState на graph/NPC position hot-path', () => {
|
||||
const index = fs.readFileSync(path.join(here, 'index.ts'), 'utf8');
|
||||
const createWindows = fs.readFileSync(path.join(here, 'windows/createWindows.ts'), 'utf8');
|
||||
const npcsEditor = fs.readFileSync(
|
||||
path.join(here, '../renderer/npcs/NpcsEditorApp.tsx'),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
assert.ok(index.includes('sendToAppWindows(ipcChannels.session.stateChanged'));
|
||||
assert.ok(createWindows.includes('SESSION_STATE_WINDOW_KINDS'));
|
||||
assert.ok(createWindows.includes('sendToAppWindows'));
|
||||
const kindsBlock = /SESSION_STATE_WINDOW_KINDS: readonly WindowKind\[\] = \[([\s\S]*?)\] as const/.exec(
|
||||
createWindows,
|
||||
);
|
||||
assert.ok(kindsBlock, 'SESSION_STATE_WINDOW_KINDS объявлен');
|
||||
assert.doesNotMatch(kindsBlock[1] ?? '', /'editor'/, 'editor не получает session.stateChanged');
|
||||
assert.match(kindsBlock[1] ?? '', /'presentation'/);
|
||||
assert.match(kindsBlock[1] ?? '', /'control'/);
|
||||
|
||||
// Handlers больше не вызывают emitSessionState сразу после layout-update.
|
||||
const npcPosHandler =
|
||||
/registerHandler\(ipcChannels\.project\.updateNpcPosition,\s*async\s*\(\{ npcId, x, y \}\) => \{([\s\S]*?)\}\);/.exec(
|
||||
index,
|
||||
);
|
||||
const graphPosHandler =
|
||||
/registerHandler\(ipcChannels\.project\.updateSceneGraphNodePosition,\s*async\s*\(\{ nodeId, x, y \}\) => \{([\s\S]*?)\}\);/.exec(
|
||||
index,
|
||||
);
|
||||
assert.ok(npcPosHandler, 'updateNpcPosition handler');
|
||||
assert.ok(graphPosHandler, 'updateSceneGraphNodePosition handler');
|
||||
assert.doesNotMatch(npcPosHandler[1] ?? '', /emitSessionState/);
|
||||
assert.doesNotMatch(graphPosHandler[1] ?? '', /emitSessionState/);
|
||||
assert.match(npcPosHandler[1] ?? '', /return \{ project \}/);
|
||||
assert.match(graphPosHandler[1] ?? '', /return \{ project \}/);
|
||||
|
||||
assert.ok(npcsEditor.includes('updateNpcPosition'));
|
||||
assert.match(
|
||||
npcsEditor,
|
||||
/onNodePositionCommit[\s\S]*?setSession\([\s\S]*?npcs: prev\.project\.npcs\.map/,
|
||||
);
|
||||
assert.match(npcsEditor, /await api\.invoke\(ipcChannels\.project\.updateNpcPosition/);
|
||||
});
|
||||
@@ -10,7 +10,7 @@ import { safeConsoleError } from '../safeConsole';
|
||||
import { getBootSplashWindow } from './bootWindow';
|
||||
import { loadBrandingWindowIcon } from './brandingIcon';
|
||||
|
||||
type WindowKind =
|
||||
export type WindowKind =
|
||||
| 'editor'
|
||||
| 'presentation'
|
||||
| 'control'
|
||||
@@ -19,6 +19,15 @@ type WindowKind =
|
||||
| 'npcsEditor'
|
||||
| 'npcs';
|
||||
|
||||
/** Окна, которые реально слушают session.stateChanged (редактор синхронизируется через invoke). */
|
||||
export const SESSION_STATE_WINDOW_KINDS: readonly WindowKind[] = [
|
||||
'presentation',
|
||||
'control',
|
||||
'materials',
|
||||
'npcs',
|
||||
'npcsEditor',
|
||||
] as const;
|
||||
|
||||
const windows = new Map<WindowKind, BrowserWindow>();
|
||||
|
||||
let appQuitting = false;
|
||||
@@ -63,6 +72,23 @@ export function markAppQuitting(): void {
|
||||
appQuitting = true;
|
||||
}
|
||||
|
||||
/** Точечная рассылка в известные окна приложения (без splash / чужих BrowserWindow). */
|
||||
export function sendToAppWindows(
|
||||
channel: string,
|
||||
payload: unknown,
|
||||
kinds: readonly WindowKind[] = SESSION_STATE_WINDOW_KINDS,
|
||||
): void {
|
||||
for (const kind of kinds) {
|
||||
const win = windows.get(kind);
|
||||
if (!win || win.isDestroyed() || win.webContents.isDestroyed()) continue;
|
||||
try {
|
||||
win.webContents.send(channel, payload);
|
||||
} catch {
|
||||
/* окно могло закрыться между проверкой и send */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function quitAppFromEditorClose(): void {
|
||||
markAppQuitting();
|
||||
app.quit();
|
||||
|
||||
Reference in New Issue
Block a user