Summary
Second-pass performance/code-quality audit finding. MemoryTransport uses a PHP array as a FIFO waiter queue, then wakes the oldest waiter with array_shift, which reindexes the entire array.
Evidence
src/Transport/MemoryTransport.php:26 declares $waiters as a list<DeferredFuture<Envelope|null>>.
src/Transport/MemoryTransport.php:63 checks whether waiters exist.
src/Transport/MemoryTransport.php:64 calls array_shift($this->waiters) for FIFO delivery.
src/Transport/MemoryTransport.php:87 through src/Transport/MemoryTransport.php:95 rebuilds the full waiter list when a receiver is cancelled.
Why it matters
Every delivery to a waiting receiver is O(n) in the number of waiters. Cancellation also scans and rebuilds the entire list. The in-memory transport is used heavily by tests and in-process scenarios, so waiter-heavy tests can degrade quadratically and hide transport behavior behind queue overhead.
Proposed fix
Store waiters in SplQueue or an indexed deque-like structure. If arbitrary cancellation removal is required, assign waiter IDs and lazily skip cancelled waiters when dequeuing.
Acceptance criteria
- FIFO wakeup is O(1) in the common case.
- Cancellation does not rebuild the whole waiter list for every cancelled receive.
- Existing memory-transport ordering tests still pass, with a new test covering many pending receivers.
Summary
Second-pass performance/code-quality audit finding.
MemoryTransportuses a PHP array as a FIFO waiter queue, then wakes the oldest waiter witharray_shift, which reindexes the entire array.Evidence
src/Transport/MemoryTransport.php:26declares$waitersas alist<DeferredFuture<Envelope|null>>.src/Transport/MemoryTransport.php:63checks whether waiters exist.src/Transport/MemoryTransport.php:64callsarray_shift($this->waiters)for FIFO delivery.src/Transport/MemoryTransport.php:87throughsrc/Transport/MemoryTransport.php:95rebuilds the full waiter list when a receiver is cancelled.Why it matters
Every delivery to a waiting receiver is O(n) in the number of waiters. Cancellation also scans and rebuilds the entire list. The in-memory transport is used heavily by tests and in-process scenarios, so waiter-heavy tests can degrade quadratically and hide transport behavior behind queue overhead.
Proposed fix
Store waiters in
SplQueueor an indexed deque-like structure. If arbitrary cancellation removal is required, assign waiter IDs and lazily skip cancelled waiters when dequeuing.Acceptance criteria