[Ovmsdev] Duktape JSON vs. CBOR serialization performance

Michael Balzer dexter at expeedo.de
Sat Aug 28 22:34:45 HKT 2021


when debugging some lost events due to Duktape queue overflows, I 
stumbled across a major Duktape performance issue in the JSON 
serialization support: encoding the AuxBatMon history data object of 5 
arrays with 1440 numbers each (JSON size ~ 30 K) took ~ 12 seconds.

I searched the Duktape repository for this and found a "fastpath" 
optimization we can use but didn't enable, so I tried that: that took 
down the encoding time to ~ 8 seconds. Unfortunately, that's as good as 
it gets with JSON in Duktape.

So I checked the CBOR support 
(https://duktape.org/guide.html#builtin-cbor), and that works much 
better. Encoding the AuxBatMon history to CBOR takes ~ 500 ms. That's 
still not really good, but acceptable.

To enable using CBOR for data exchange with the web frontend as well, 
I've included the CBOR-JS library by Patrick Gansterer, and added a 
binary output option for Javascript commands. I've changed the AuxBatMon 
and PwrMon plugins to use CBOR instead of JSON, and both work and load 
much faster now.

I strongly suggest updating the plugins if you use them.

If you implement a plugin with some kind of data storage or transfer of 
larger objects to the web frontend, do not use JSON, use CBOR instead. 
I've added a section to our manual on this:



Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openvehicles.com/pipermail/ovmsdev/attachments/20210828/59eb7e19/attachment.sig>

More information about the OvmsDev mailing list