canboat / canboatjs

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

refactor: optimise object creation & remove spread #265

Closed tkurki closed 3 months ago

tkurki commented 4 months ago

This came up during a recent profiling session: there's a hotspot here, using the spread operator to create a new object.

With server processing an n2k file with the server with "noThrottle": true for the simple stream configuration, multiplexed file playback the baseline throughput was 35k deltas/s and with small change it jumped to 45k deltas/s, so not an insignificant change.

I have not looked into any deeper: does this really need to construct a new object? Or can it just modify the incoming object? All tests pass, but I am really no expert with this codebase, so please have a deeper look.

tkurki commented 4 months ago

I pushed another version/commit, this one is clocking around 48k deltas/s. Now the object is copied.

The comment is a little confusing to me: all incoming properties are copied as is, but overridden by the other parameters and added, so not remove or add is not quite accurate for the original functionality.