Skip to content
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

Consider using heapless::Vec #167

Open
geonnave opened this issue Dec 8, 2023 · 2 comments
Open

Consider using heapless::Vec #167

geonnave opened this issue Dec 8, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@geonnave
Copy link
Collaborator

geonnave commented Dec 8, 2023

I was not aware of Vec in the heapless crate until recently when mentioned by @chrysn. Now it seems that EdhocMessageBuffer is growing to be more and more like a re-implementation of that. Thus, it may make sense to just switch and use heapless::Vec.

Considerations:

  • Binary size: I did a quick test in the no-std example and it added only 1 KB to the binary size
  • Hax: need to check if / how it would have an impact there
@geonnave geonnave changed the title Consider using heapless' Vec Consider using heapless::Vec Dec 8, 2023
@chrysn
Copy link
Collaborator

chrysn commented Dec 8, 2023

My guess at the main difference is that heapless (wohoo, of which there is 0.8.0 now!) would uses MaybeUninit and unsafe, whereas EdhocMessageBuffer is safe at the cost of initial nulling.

A proof that heapless indeed never reads from uninitialized memory would be awesome, but may also not be a priority.

Unless hax just makes magic happen already anyway, a practical option may be to evolve EdhocMessageBuffer to a point where it is a (safe, null-initializing) drop-in replacement to heapless. Then, lakers-shared could have a feature to enable either the built-in (proof friendly and thus known to be safe) structure, or pub use heapless::Vec as MessageBuffer; (which saves flash by reusing an implementation likely used elsewhere, and enhances performance by foregoing the nulling).

On the long run, this path could converge onto using heapless if and when hax manages to prove that heapless::Vec is publicly equivalent to our message buffer.

@geonnave
Copy link
Collaborator Author

geonnave commented Dec 8, 2023

Sounds like a good plan, thanks for providing more detail.

@geonnave geonnave added the wontfix This will not be worked on label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants