newcat / baklavajs

Graph / node editor in the browser using VueJS
http://baklava.tech
MIT License
1.57k stars 116 forks source link

Serious problem:The calculation speed is very, very slow. #381

Closed chuteany closed 7 months ago

chuteany commented 8 months ago
  1. The calculation of the following graph took around 28 seconds in total. image
  2. The calculation of the following graph took around 45 seconds in total. image

Would converting the graph into a function and then computing it be faster?

chuteany commented 8 months ago

I also spent roughly the same amount of time executing they in the Node.js environment.

newcat commented 8 months ago

Can't reproduce - I exactly used the first graph and it took such a short amount of time that it didn't even appear in the Chrome performance flamechart, so less than 0.1 ms. Maybe you do something very expensive in the calculate functions of your node implementations other than just calculating the value?

chuteany commented 7 months ago

Sorry, it's my own problem.

I have used Promise and setTimeout in calculate function when return;

`import { defineNode, NodeInterface } from "@baklavajs/core"; import { NumberInterface, SelectInterface } from "../src";

export default defineNode({ type: "Math", inputs: { number1: () => new NumberInterface("Number", 1), number2: () => new NumberInterface("Number", 10), operation: () => new SelectInterface("Operation", "Add", ["Add", "Subtract", "Mul", "Div"]).setPort(false), }, outputs: { output: () => new NodeInterface("Output", 0), }, calculate({ number1, number2, operation }) { let output: number; if (operation === "Add") { output = Number(number1) + Number(number2); } else if (operation === "Subtract") { output = Number(number1) - Number(number2); } else if (operation === "Mul") { output = Number(number1) * Number(number2); } else if (operation === "Div") { output = Number(number1) / Number(number2); } else { throw new Error(Unknown operation: ${operation}); } return new Promise((resolve, reject) => { setTimeout(() => { resolve({ output }) ; }, 3000); }) }, });`