canboat / canboatjs

Native javascript NMEA 2000 decoder and encoder
Apache License 2.0
95 stars 39 forks source link

Optimizing object creation #247

Closed tkurki closed 2 weeks ago

tkurki commented 11 months ago

One of the most prevalent Node/V8 performance tips is https://web.dev/speed-v8/#therefore

On my modern Mac signalk-server settles at about 39 k deltas per second, playing back n2k-from-file full blast.

With this change

exports.parseActisense = (input) => {
  const [ timestamp, prio, pgn, src, dst, len, ...data ] = input.split(',')
  return {
    prio: Number(prio),
    pgn: Number(pgn),
    dst: Number(dst),
    src: Number(src),
    format: 'Actisense',
    data: Buffer.from(data.join(''), 'hex'),
    len: Number(len),
    timestamp
  }
  // return buildMsg(
  //   buildCanId(prio, pgn, dst, src),
  //   'Actisense',
  //   Buffer.from(data.join(''), 'hex'),
  //   { len: Number(len), timestamp },
  // )
}

it manages 47 k deltas/s - quite a difference! An artificial benchmark, with no clients etc, but still.