I am onto my next Node-RED project, this time rebuilding the LUA based automated lighting for my house on NR and using uibuilder as the interface.
I have a function node which could contain at least 15 functions within it that would be called within the one function node, however what I really LOVE about NR is that I can split my code out into nice modules which makes it easier to debug, write, maintain etc etc
I have conceptually split out the ~15 functions into 12 separate function nodes, and am using split nodes to coordinate the flow from the start function through to the end function.
I am about to start coding, but then I started to wonder whether I had made a mistake in terms of performance.
I am absolutely (pig-headed even) sure that the design is light years ahead of using one huge function node which in reality will be a beep to code, debug, maintain etc etc, but I am now wondering what the overhead is of having 12+ function nodes where I had one before.
The routing and redirecting from one function node to the next will not take up any extra code than if it was in one function node (as you might expect), but I don't know how NR works in terms of loading into memory and processing ... is it better to load it into memory once via one function node or does it not really matter that I have created a web/tree of function nodes.
Whether it was one or 12 functions nodes, the code will loop between 1 and 20 times to complete one cycle. Not sure if that changes anything... i.e. in the one function node, there will be a: "x.forEach(item =>" that runs up to 20 times per cycle. With the 12 function nodes, the first function node will spit out data for each of the 20 runs and these will run through some or all of the remaining 11 nodes - depending on the reference data provided e.g. one set of data may run through 2 functions and the next through all 12, although it's unlikely any will actually run through all 12 given the nature of the code.
Appreciate there may be more questions than answers on this one, but hoping I've given enough info.
EDIT: The code has to be performant / run in milliseconds. I anticipate when it's running that it will be triggered every 1 second at a maximum.