Parallel nodes efficiency

Hello guys, how does Node-red calculate parallel nodes? If you have 100 parallel function nodes with a single if clause vs one node with 100 consecutive if's, which one would be faster?

Node.js is single-threaded, so there is no immediate benefit to making your flows more parallel. In fact that can just make it more complicated as you then may need to join those parallel branches back together.

You also have the overhead of passing messages to each of those branches - particularly if they have to be cloned along the way.

In terms of the Function node, there is also a slight overhead involved with the sandbox used by the node (more typically a memory-usage overhead rather than performance through-put).

So I would always expect a single Function node with lots of if statements to be 'faster' than a flow with hundreds of Function nodes.

1 Like

Hi @kuzmich,

If this is an academic question the Nick has answered it :+1:

If this is something you're doing or thinking of doing, you might want to post a small example, there is possibly a much better way of achieving what you're attempting to achieve.

I'm implementing a Telegram bot into my automatisation and it uses inline keyboard. When i evaluate callback data, at some point i need to make the bot post 2 consecutive replies - one is "delete the keyboard" and second is the actual post with info. So now i'm choosing between these two variants, but i was wondering about efficiency if this "tree" becomes more complicated, so i made the post.
P.S. number 100 was an obvious exaggeration to make things simpler :wink:

From a manageability POV, I would chose the 1st version (1 function to evaluate)

However instead of a large bunch of if else if or a large switch case I'd explore the possibility of a lookup.


Inject (on start up) > function (initialise lookup from fixed data or database)

This lookup would likely be an array of objects or a dictionary or an object of keys to object (a lookup) stored in context for quick retrieval


let lu = {
 "help" : {
    "keyboard" : {...},
    "response" : {...},
  "get main line status"  : {
    "keyboard" : {...},
    "response" : {...},
flow.set("lookup", lu);

And in your "evaluate callback" function, you can simply lookup and process reply...

let userInput = msg.payload;
let lu = flow.get("lookup") || {};
let o = lu[userInput];
  // Send msg with o.keyboard to set the correct keyboard
  // process the options in o.response object and send the reply to user
} else {
   // Send msg to set the 'What Do You Want To Do' keyboard
  // Send "Sorry, I didn't understand" response to user

In other words, the code in your function becomes pretty much an unchanging dynamic bit of code that operates on the settings set in context.

The advantages of this is you could end up building a web based dashboard or application that lets you update the lookup on the fly or pass the maintenance of lookup responses on to a non developer.

I know my response is idyllic / simplistic and quite possibly not suitable for your application but I hope it spurs you on to a light bulb moment.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.