Skip to content

perf(semaphore): store wake batch on stack - #190

Merged
tisonkun merged 3 commits into
mainfrom
codex/semaphore-stack-wake-list
Aug 26, 2026
Merged

perf(semaphore): store wake batch on stack#190
tisonkun merged 3 commits into
mainfrom
codex/semaphore-stack-wake-list

Conversation

@tisonkun

Copy link
Copy Markdown
Member

Summary

  • replace the lazily allocated Vec<Waker> in semaphore release with a fixed 32-slot stack batch
  • preserve the existing unlock-before-wake batching and FIFO wake order
  • keep panic cleanup explicit: start..end is the only initialized range, and advancing start before wake lets unwind drop the remaining wakers

This is stacked on #189 so the Waker correctness changes remain independently reviewable.

A shorter [Option<Waker>; 32] prototype regressed the empty-queue release benchmark by about 18%. The final MaybeUninit helper avoids initializing unused slots and keeps a single documented invariant.

Benchmarks

Apple Silicon, medians, alternating this branch with #189 using 0.5s minimum time and 80 samples:

Benchmark #189 This PR Change
handoff_permit 124.4 ns 82.55 ns -33.6%
queued_owned_burst/1 249.4 ns 207.5 ns -16.8%
queued_owned_burst/8 665.4 ns 556.8 ns -16.3%
queued_owned_burst/32 2.290 us 1.812 us -20.9%
release 22.11 ns 20.71 ns -6.3%

Command:

cargo bench -p benchmarks --bench benchmarks -- semaphore::handoff_permit semaphore::queued_owned_burst semaphore::release --min-time 0.5 --sample-count 80 --color never

Testing

  • cargo +1.86.0 check -p asyncband --all-features
  • cargo x lint
  • cargo x test --no-capture

Base automatically changed from codex/semaphore-waker-safety to main August 26, 2026 01:23
@tisonkun
tisonkun merged commit cc4db52 into main Aug 26, 2026
9 checks passed
@tisonkun
tisonkun deleted the codex/semaphore-stack-wake-list branch August 26, 2026 01:35
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.

1 participant