Skip to content

Replace Array.removeFirst in Mailbox with an O(1) queue #49

@nficano

Description

@nficano

Mailbox.next() removes the first buffered element with buffer.removeFirst() at Sources/ARCP/Runtime/Mailbox.swift:36. Array.removeFirst() shifts the remaining elements, so draining a large backlog of envelopes becomes quadratic in the number of buffered messages. Mailbox sits on the client and runtime receive path, so this affects resume, subscriptions, and any bursty transport where messages arrive faster than logical consumers process them.

Fix prompt: Replace the array-front removal with an O(1) queue strategy. A simple head index with periodic compaction keeps the current dependency set unchanged, while adopting a deque type would also be appropriate if the package adds Swift Collections directly. Add a focused performance or behavior test that enqueues and drains a large number of envelopes without relying on repeated array shifting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions