Pros and Cons about using "custom" Functions vs the basic set of nodes

Great work, thanks for doing this. Really useful.

1 Like

@kazuhitoyokoi - do you have a simple set of steps to create the nodegen fuction blocks? Or do I have to wade thru that info to create them?

The README.md in node-red-nodegen project has simple steps to create nodegen function nodes as follows.

## Installation
* sudo npm install -g node-red-nodegen

### Create original node from function node
* On Node-RED flow editor, save function node to library with file name (lower-case.js).
* node-red-nodegen ~/.node-red/lib/function/lower-case.js
* cd node-red-contrib-lower-case
* sudo npm link
* cd ~/.node-red
* npm link node-red-contrib-lower-case
* node-red
-> You can use lower-case node on Node-RED flow editor.

You can also create "function node without vm module" using the following steps.

## Installation
* git clone https://github.com/kazuhitoyokoi/node-red-nodegen.git
* cd node-red-nodegen
* git checkout master-functionwithoutvm
* npm install

### Create original node from function node
* On Node-RED flow editor, save function node to library with file name (lower-case.js).
* node bin/node-red-nodegen.js ~/.node-red/lib/function/lower-case.js --name lower-case-wovm
* cd node-red-contrib-lower-case-wovm
* sudo npm link
* cd ~/.node-red
* npm link node-red-contrib-lower-case-wovm
* node-red
-> You can use lower-case-wovm node on Node-RED flow editor.

In the future, Node-RED flow editor will be able to have nodegen UI. Currently there is the design note about the UI.

I've just pushed a fix to git that restores the performance of the Switch node:

Number of messages Function Time (ms) Switch Time (ms)
16384 1216 331
32768 2081 600
65536 4125 1124
131072 8282 2207

This fix only applies if the node doesn't try to access context.

I suspect a similar performance regression will have been introduced to the Change node - I'll sort that out next.

3 Likes

Thank you for the optimization. :slight_smile: I'll use the new version of Node-RED!

That’s a great point! Using normal nodes is often the best way because they are built to run smooth and use less processor power, especially for simple tasks. But when you need to handle something more complex, writing your own code in Function nodes can make the flow cleaner and easier to understand. Just be careful, because if the code inside a Function node is too long or not written well, it can slow things down. The best idea is to mix both. Use normal nodes for simple jobs and use Function nodes only when you really need custom logic. This way of thinking is also very helpful in app development in Dubai, where apps need to work fast and stay easy to update at the same time. I would also like to hear what others think about this.