valpackett / SwiftCBOR

A CBOR implementation for Swift
The Unlicense
132 stars 74 forks source link

Massive performance improvements by switching from using Data to ArraySlice #67

Closed martinreichart closed 3 years ago

martinreichart commented 3 years ago

Another massive performance improvement for decoding. The decoder and decoding containers previously used to constantly create new Data objects while parsing the payload (suffix in combination with map) leading to hundreds of thousands recreated data structures even while parsing a small payload. This change massively improves the performance by completely switching to ArraySlice for the individual bytes instead of recreating objects.

The attached images show the before and after for test cases we have written which parse the data from the Acceptance System of the Austrian Gateway for EU Digital COVID Certificates (See https://github.com/Federal-Ministry-of-Health-AT/green-pass-overview for the endpoints about trustlist, business rules and value sets) which improves the parsing speed by a factor of 60 (from 80 seconds to 2 seconds) when testing in the simulator, while real world improvements are even more dramatic and become greater with device age.

before after
hamchapman commented 3 years ago

Awesome! Very nice indeed 😁 Thanks for taking a further look into this and great job making such a massive improvement 🙌