From a405a21c483c9276b99ec5fffe26984a4ff89d75 Mon Sep 17 00:00:00 2001 From: Jesse Ezell Date: Wed, 22 Jan 2020 14:04:19 -0800 Subject: [PATCH] fix performance related issue where multiple connections results in exponential amounts of work --- src/engine/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/engine/index.ts b/src/engine/index.ts index ba20d787..26fdf132 100644 --- a/src/engine/index.ts +++ b/src/engine/index.ts @@ -18,6 +18,7 @@ export class Engine extends Context { args: unknown[] = []; data: Data | null = null; state = State.AVAILABLE; + forwarded = new Set(); onAbort = () => { }; constructor(id: string) { @@ -156,15 +157,16 @@ export class Engine extends Context { private async forwardProcess(node: NodeData) { if (this.state === State.ABORT) return null; - + return await Promise.all(Object.keys(node.outputs).map(async (key) => { const output = node.outputs[key]; - return await Promise.all(output.connections.map(async (c) => { const nextNode = (this.data as Data).nodes[c.node]; - - await this.processNode(nextNode as EngineNode); - await this.forwardProcess(nextNode); + if(!this.forwarded.has(nextNode)) { + this.forwarded.add(nextNode); + await this.processNode(nextNode as EngineNode); + await this.forwardProcess(nextNode); + } })); })); } @@ -225,10 +227,11 @@ export class Engine extends Context { this.data = this.copy(data); this.args = args; + this.forwarded = new Set(); await this.processStartNode(startId); await this.processUnreachable(); return this.processDone()?'success':'aborted'; } -} \ No newline at end of file +}