Speed up split node

fixes #5251

The code changed from 4.0.x to 4.1.x

This change to to prevent making changes to the orginial input `msg`
object incase any values were stored in context (pass by refernce).

The change meant that for every output message the whole original
input `msg` was being cloned, which could be huge, causing a big
performance regresion.

This fix ensures the clone of the orginial `msg` is only done once
and the much smaller output message is then cloned again to update
`msg.parts` object for each output. This results in lots of small
clones rather than lots of very large clones.
This commit is contained in:
Ben Hardill
2025-08-20 18:40:19 +01:00
parent 9bf42037b5
commit 22a3f47060

View File

@@ -146,16 +146,16 @@ module.exports = function(RED) {
var pos = 0;
var data = value;
msg.parts.len = node.arraySplt;
const newmsg = RED.utils.cloneMessge(msg)
for (var i=0; i<count; i++) {
var m = data.slice(pos,pos+node.arraySplt);
if (node.arraySplt === 1) {
m = m[0];
}
const newmsg = RED.util.cloneMessage(msg)
RED.util.setMessageProperty(newmsg,node.property,m);
newmsg.parts.index = i;
pos += node.arraySplt;
send(newmsg);
send(RED.utils.cloneMessage(newmsg));
}
done();
}