Hi all. This is literally my second day using n8n so if I’m completely off base please let me know.
Describe the issue/error/question
The performance of he Crypto node MD5 calculation was slower than I expected/need, the nodejs crypto.createHash() is pretty quick so I did some digging.
Across 1000 items using the original code the workflow was taking around 1.5 minutes, most of this was in the Crypto node.
I poked around in the code and found \Crypto\Crypto.node.js
. Noted that there is quite a bit of what I’d call “extra” code within the for loop, lots of this.getNodeParameter()
calls on each item. The values that these calls are returning should be consistent across all items.
I ended up making some changes to the js file directly, just to see the performance change.
Crypto.js code releates to the ts around here
async execute() {
const items = this.getInputData();
const returnData = [];
const length = items.length;
const action = this.getNodeParameter('action', 0);
let item;
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0)
const valueKey = this.getNodeParameter('value', 0);
const type = this.getNodeParameter('type', 0)
const encoding = this.getNodeParameter('encoding', 0);
console.log(valueKey);
for (let i = 0; i < length; i++) {
try {
item = items[i];
console.log(item);
const value = item.json[valueKey];
let newValue;
if (action === 'hash') {
newValue = crypto_1.createHash(type).update(value).digest(encoding);
}
...
After this change I found that the workflow could process the same 1000 items in under 3 seconds! With very little time spent in the Crypto node.
I’m well aware that my change is a kludge and not generic or suitable (lol), but it does show there is significant scope to improve this performance.
This raises a couple of questions. Is this pattern of iterating all items and pulling values using this.getNodeParameter()
for each item common in many nodes? Is it expected that this operation i.e. this.getNodeParameter()
would have such a significant impact on performance? In the MD5 case, all the parameters pulled are the same except the actual value being hashed, I just followed the lead of the “action” property and pulled them all from the first item, any reason why that wouldn’t work?
Or is this all just some quirk in my very simplistic setup?
Information on your n8n setup
- n8n version: 0.162.0
- Database you’re using (default: SQLite): SQLite
- Running n8n with the execution process [own(default), main]: default
- Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm on Windows