Did some optimizations for your function. Left in comments to explain the changes.
As I don't have any PI (or similar low performance machine) I really can't say will it help or how much it changes .
For performance gain, node-red-contrib-unsafe-function (node) - Node-RED is faster than regular function.
var values = msg.payload.trim().split(",");
// the need of trim.() should be avoided at data creation.if(values.length < 5){
// if parsing does not create all elements, then do nothing and return early
return
}// data considered to be ok. create output.
msg.topic="sensor-data";// removed outMsg object
// temporary object creation, if not needed is just waist of memory.
// Lack of memory affects also CPU usage.// parseFloat does not provide radix option!
// parseFloat(string, radix) does not fire any error but also has no effect// parseFloat(string) returns NaN if value can not be converted to number
// if NaN happened, assigne default (-999.0)msg.payload = {
rate: parseFloat(values[0]) || -999.0,
xaxis: parseFloat(values[1]) || -999.0,
yaxis: parseFloat(values[2]) || -999.0,
zaxis: parseFloat(values[3]) || -999.0,
temp: parseFloat(values[4]) || -999.0
}return msg;