Skip to content

Avoid cloning Embassy mailbox values#192

Merged
lxsaah merged 2 commits into
aimdb-dev:mainfrom
floze-the-genius:perf/186-embassy-mailbox-no-clone
Jul 18, 2026
Merged

Avoid cloning Embassy mailbox values#192
lxsaah merged 2 commits into
aimdb-dev:mainfrom
floze-the-genius:perf/186-embassy-mailbox-no-clone

Conversation

@floze-the-genius

Copy link
Copy Markdown
Contributor

Description

The Embassy mailbox push path cloned every value before its first try_send, even when the single slot was empty. Recover the rejected value from TrySendError::Full instead, drain the stale slot opportunistically, and retry with the same owned value.

The retry remains unconditional after a full result, preserving the race where a receiver drains the old item between the failed send and the overwrite attempt. Single-slot latest-value-wins behavior is unchanged.

A clone-counting regression verifies zero payload clones for both an empty-slot push and a full-slot overwrite.

Related Issue

Verification

  • Exact clone-counting regression: 1 passed
  • Full aimdb-embassy-adapter: 16 unit, 3 connector, 1 session, and 4 doctests passed; 1 doctest ignored
  • Strict adapter library clippy with -D warnings: passed
  • cargo fmt -p aimdb-embassy-adapter -- --check: passed
  • git diff --check: passed

The embedded thumbv7em-none-eabihf check could not run on this host because the installed Homebrew Rust toolchain has no rustup or embedded target (E0463: can't find crate for core). The repository-wide all-targets clippy also reaches an unrelated existing default_constructed_unit_structs lint in tests/session_smoke.rs:115; the changed library target is clean.

Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the project's coding standards.
  • I have added tests to cover my changes.
  • All new and existing tests passed (make check).
  • Documentation changes are not required for this internal performance fix.

Recover the rejected value from TrySendError::Full and reuse it after draining the stale slot. Add clone-counting coverage for empty and full mailbox pushes while preserving latest-value-wins semantics.
@floze-the-genius
floze-the-genius requested a review from lxsaah as a code owner July 18, 2026 10:25

@lxsaah lxsaah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@lxsaah
lxsaah merged commit e6eb682 into aimdb-dev:main Jul 18, 2026
6 checks passed
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.

Embassy adapter: eliminate the unconditional clone in Mailbox push

2 participants