quotient-im / libQuotient

A Qt library to write cross-platform clients for Matrix
https://quotient-im.github.io/libQuotient/
GNU Lesser General Public License v2.1
132 stars 56 forks source link

Deserialize CBOR data without one allocation per value #772

Closed vkrause closed 2 months ago

vkrause commented 2 months ago

QCBorValue::toJsonValue checks whether the CBOR data is in the JSON subset, which results in one allocation per value. As this is our own serialized data here, we don't need that check and can use the CBOR data directly.

The API for that fast path is unfortunately not public, but it's inline code, so it doesn't bind us to Qt's unstable internal ABI either.

This saves about 12M allocations during the startup of Itinerary here.

KitsuneRal commented 2 months ago

Ah yes, I've seen fromTrustedCbor() but didn't know how to use it; and yes the inefficiency has always bugged me too. Thanks for the trick!