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

Remove alloc and bytes dependency #136

Merged
merged 5 commits into from
Nov 21, 2022

Conversation

qwerty19106
Copy link
Contributor

Mavlink can be used in no_std mode, for example for thumbv7em-none-eabihf target (Cortex-M microcontrollers).
Heap usage is very bad idea for microcontrollers. It introduces uncontrollable latency and unacceptable for some tasks such as motor control.

  1. Mavlink frame has fixed size: up to 263 bytes for Mavlink V1, up to 280 bytes for Mavlink V2 (MAVLink Packet Format).
    I replaced all std::Vec (alloc::Vec) to stack allocated heapless::Vec.

  2. The struct bytes::BytesMut is no support no_std mode. Its API and code very requires on std::Vec.
    Moreover BytesMut use BufMut API with chunk_mut method. Due to BytesMut::put_* and BytesMut::get_* methods use while cycle with code, which can not be optimized by compiler (loop unwinding). It is very slow.
    Therefore I replace bytes::BytesMut on two small (320 lines summary) and fast structs Bytes and BytesMut with analoguous API.

  3. I replaced all String usages to &'static str.

It is breaking changes, but it increase perfomance in std mode too.

Copy link
Contributor

@Erk- Erk- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small things, this is a nice change overall

build/parser.rs Outdated Show resolved Hide resolved
src/bytes_mut.rs Outdated Show resolved Hide resolved
@qwerty19106 qwerty19106 changed the title WIP: Remove alloc and bytes dependency Remove alloc and bytes dependency Nov 15, 2022
@qwerty19106
Copy link
Contributor Author

It is ready to review.

@qwerty19106
Copy link
Contributor Author

Embedded example was been updated too.

Cargo compile crc-any dependency with build-dependencies features for this example. Thus example can not been compiled due to alloc dependency.
It is very ugly! I add default-features = false into crc-any build-dependency to prevent it.

@patrickelectric
Copy link
Member

@qwerty19106 please check CI

@qwerty19106
Copy link
Contributor Author

The cargo fmt errors are fixed.

@patrickelectric
Copy link
Member

The cargo fmt errors are fixed.

You need to rebase over master since the branch has conflicts now.

@qwerty19106
Copy link
Contributor Author

Rebased

@patrickelectric
Copy link
Member

We can let as it's for now, but for future PRs, you should apply the rustfmt changes on their specific commits.

@patrickelectric
Copy link
Member

And thanks for the contribution!

@patrickelectric patrickelectric merged commit b7e7e29 into mavlink:master Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants