-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CBOR maps use Vec instead of BTreeMap #303
Conversation
Could you provide from which number the binary size is reduced from in the description? (both for base reference and history) Ex: Binary size is reduced from XXX.X KiB to 126.9 KiB. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM.
One question: CBOR being canonical, I guess that there's unicity on the keys in a map. Do we have a test for that and isn't an implementation based on Vec<>
problematic here (i.e. we would need to sort then check for duplicate keys)?
True! Dedup and test added. The new binary size is 127.3 KiB, and I edited above correctly state the prior size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (wasn't planning to review it, it's just that when giving an improvement it's good to have both old and new value to understand the impact)
We only access CBOR maps by iterating over them. They also have to be sorted, but that is asserted when reading, and as we control the inputs, we can output the elements in the correct order (we do sort before writing though, to make sure). Therefore, maps can be represented internally by
Vec<Key, Value>
.This change intends to reduce the binary size and RAM usage of OpenSK.
BTreeMap
have been the largest when analyzed.BTreeMap
allocates lots of memory.This changes removes all occurances of BTreeMap. Binary size in optimized mode is reduced from 130.5 KiB to 126.9 KiB as output by:
This PR also cleans up some test code:
cbor_array_vec
is only used when actually needing to take avec
, not for `cbor_array_vec[vec![...]]sort_by
call incbor::writer
could be removed)All changes made are (impactful) implementation details, but we don't change any behaviour.