fix: GraphCanvas performance fixes (Phase 2)

- Remove deep: true from progress watcher

- Hoist useWorkflowStore() outside loop

- Add run-id race guards to async watchers (palette, background, locale)

Amp-Thread-ID: https://ampcode.com/threads/T-019bf961-0a09-71f3-93ac-8166b25ded66
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Alexander Brown
2026-01-26 00:19:17 -08:00
parent 14f11cd51e
commit bbec515a7b

View File

@@ -294,15 +294,18 @@ watch(
} }
) )
let paletteWatcherRunId = 0
watch( watch(
[() => canvasStore.canvas, () => settingStore.get('Comfy.ColorPalette')], [() => canvasStore.canvas, () => settingStore.get('Comfy.ColorPalette')],
async ([canvas, currentPaletteId]) => { async ([canvas, currentPaletteId]) => {
if (!canvas) return if (!canvas) return
const runId = ++paletteWatcherRunId
await colorPaletteService.loadColorPalette(currentPaletteId) await colorPaletteService.loadColorPalette(currentPaletteId)
if (runId !== paletteWatcherRunId) return
} }
) )
let backgroundWatcherRunId = 0
watch( watch(
() => settingStore.get('Comfy.Canvas.BackgroundImage'), () => settingStore.get('Comfy.Canvas.BackgroundImage'),
async () => { async () => {
@@ -310,8 +313,10 @@ watch(
const currentPaletteId = colorPaletteStore.activePaletteId const currentPaletteId = colorPaletteStore.activePaletteId
if (!currentPaletteId) return if (!currentPaletteId) return
const runId = ++backgroundWatcherRunId
// Reload color palette to apply background image // Reload color palette to apply background image
await colorPaletteService.loadColorPalette(currentPaletteId) await colorPaletteService.loadColorPalette(currentPaletteId)
if (runId !== backgroundWatcherRunId) return
// Mark background canvas as dirty // Mark background canvas as dirty
canvasStore.canvas.setDirty(false, true) canvasStore.canvas.setDirty(false, true)
} }
@@ -329,8 +334,9 @@ watch(
[executionStore.nodeLocationProgressStates, canvasStore.canvas] as const, [executionStore.nodeLocationProgressStates, canvasStore.canvas] as const,
([nodeLocationProgressStates, canvas]) => { ([nodeLocationProgressStates, canvas]) => {
if (!canvas?.graph) return if (!canvas?.graph) return
const workflowStore = useWorkflowStore()
for (const node of canvas.graph.nodes) { for (const node of canvas.graph.nodes) {
const nodeLocatorId = useWorkflowStore().nodeIdToNodeLocatorId(node.id) const nodeLocatorId = workflowStore.nodeIdToNodeLocatorId(node.id)
const progressState = nodeLocationProgressStates[nodeLocatorId] const progressState = nodeLocationProgressStates[nodeLocatorId]
if (progressState && progressState.state === 'running') { if (progressState && progressState.state === 'running') {
node.progress = progressState.value / progressState.max node.progress = progressState.value / progressState.max
@@ -341,8 +347,7 @@ watch(
// Force canvas redraw to ensure progress updates are visible // Force canvas redraw to ensure progress updates are visible
canvas.setDirty(true, false) canvas.setDirty(true, false)
}, }
{ deep: true }
) )
// Update node slot errors for LiteGraph nodes // Update node slot errors for LiteGraph nodes
@@ -410,20 +415,26 @@ usePaste()
useWorkflowAutoSave() useWorkflowAutoSave()
// Start watching for locale change after the initial value is loaded. // Start watching for locale change after the initial value is loaded.
let localeWatcherRunId = 0
watch( watch(
() => settingStore.get('Comfy.Locale'), () => settingStore.get('Comfy.Locale'),
async (_newLocale, oldLocale) => { async (_newLocale, oldLocale) => {
if (!oldLocale) return if (!oldLocale) return
const runId = ++localeWatcherRunId
await until(() => isSettingsReady.value || !!settingsError.value).toBe(true)
if (runId !== localeWatcherRunId) return
await Promise.all([ await Promise.all([
until(() => isSettingsReady.value || !!settingsError.value).toBe(true), until(() => isSettingsReady.value || !!settingsError.value).toBe(true),
until(() => isI18nReady.value || !!i18nError.value).toBe(true) until(() => isI18nReady.value || !!i18nError.value).toBe(true)
]) ])
if (runId !== localeWatcherRunId) return
if (settingsError.value || i18nError.value) { if (settingsError.value || i18nError.value) {
console.warn( console.warn(
'Somehow the Locale setting was changed while the settings or i18n had a setup error' 'Somehow the Locale setting was changed while the settings or i18n had a setup error'
) )
} }
await useCommandStore().execute('Comfy.RefreshNodeDefinitions') await useCommandStore().execute('Comfy.RefreshNodeDefinitions')
if (runId !== localeWatcherRunId) return
await useWorkflowService().reloadCurrentWorkflow() await useWorkflowService().reloadCurrentWorkflow()
} }
) )