Closed chuteany closed 7 months ago
I also spent roughly the same amount of time executing they in the Node.js environment.
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?
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);
})
},
});`
Would converting the graph into a function and then computing it be faster?