The Embassy adapter's Mailbox push clones the value on every push, even
when the slot is free and the first try_send would succeed
(aimdb-embassy-adapter/src/buffer.rs):
EmbassyBufferInner::Mailbox(channel) => {
// Try to send, if full, clear and try again (overwrite semantic)
let sender = channel.sender();
if sender.try_send(value.clone()).is_err() {
let _ = channel.try_receive();
let _ = sender.try_send(value);
}
}
The clone is unnecessary: embassy_sync's try_send returns the message
back on failure — Err(TrySendError::Full(value)) — so the value can be
recovered from the error and reused for the retry. On an MCU, a per-push
clone of the payload type is real cost on the hot path.
Where to look
aimdb-embassy-adapter/src/buffer.rs — the Mailbox arm of push
embassy_sync::channel::TrySendError — the error variant carries the
rejected message
aimdb-core/src/buffer/test_support.rs — the shared contract suite that
pins the overwrite behavior across adapters
What to do
- Match on
Err(TrySendError::Full(v)), drain the stale message with
try_receive(), and resend v — no clone anywhere in the path.
- Behavior must stay observably identical (single-slot overwrite, latest
value wins); this is a pure cost fix, not a semantics change.
- The
T: Clone bound itself stays — the other buffer variants still need
it. Only the clone() call in this path disappears.
Done when
- No
clone() in the Mailbox push path
cargo test -p aimdb-embassy-adapter (contract suite included) is green
- The embedded cross-compile check passes
(cargo check --target thumbv7em-none-eabihf) and make check is green
Getting set up
CONTRIBUTING.md
covers prerequisites and the development setup. For the embedded check you
will need the cross-compile target installed:
rustup target add thumbv7em-none-eabihf.
The Embassy adapter's Mailbox
pushclones the value on every push, evenwhen the slot is free and the first
try_sendwould succeed(
aimdb-embassy-adapter/src/buffer.rs):The clone is unnecessary:
embassy_sync'stry_sendreturns the messageback on failure —
Err(TrySendError::Full(value))— so the value can berecovered from the error and reused for the retry. On an MCU, a per-push
clone of the payload type is real cost on the hot path.
Where to look
aimdb-embassy-adapter/src/buffer.rs— theMailboxarm ofpushembassy_sync::channel::TrySendError— the error variant carries therejected message
aimdb-core/src/buffer/test_support.rs— the shared contract suite thatpins the overwrite behavior across adapters
What to do
Err(TrySendError::Full(v)), drain the stale message withtry_receive(), and resendv— no clone anywhere in the path.value wins); this is a pure cost fix, not a semantics change.
T: Clonebound itself stays — the other buffer variants still needit. Only the
clone()call in this path disappears.Done when
clone()in the Mailbox push pathcargo test -p aimdb-embassy-adapter(contract suite included) is green(
cargo check --target thumbv7em-none-eabihf) andmake checkis greenGetting set up
CONTRIBUTING.md
covers prerequisites and the development setup. For the embedded check you
will need the cross-compile target installed:
rustup target add thumbv7em-none-eabihf.