Skip to content

perf(semaphore): Allocate wake buffer only when needed - #188

Merged
tisonkun merged 2 commits into
apache:mainfrom
mhambre:perf/minor-semaphore-optimization
Aug 26, 2026
Merged

perf(semaphore): Allocate wake buffer only when needed#188
tisonkun merged 2 commits into
apache:mainfrom
mhambre:perf/minor-semaphore-optimization

Conversation

@mhambre

@mhambre mhambre commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Avoids unnecessary wake buffer allocation on the semaphore release hot path when no tasks need to be woken.

cargo bench -p benchmarks --bench benchmarks -- semaphore mutex \
  --min-time 0.75 \
  --sample-count 100 \
  --color never

Median

Benchmark Before After Improvement
Mutex uncontended reuse 57.94 ns 21.15 ns 63.5%
Semaphore try-acquire/release 51.10 ns 13.82 ns 73.0%
Semaphore owned acquire/release 52.40 ns 22.61 ns 56.9%
Semaphore release 90.83 ns 43.93 ns 51.6%
Repeated permit debt 4.124 µs 1.728 µs 58.1%

Mean

Benchmark Before After Improvement
Mutex uncontended reuse 57.99 ns 21.24 ns 63.4%
Semaphore try-acquire/release 51.00 ns 13.85 ns 72.8%
Semaphore owned acquire/release 54.46 ns 22.62 ns 58.5%
Semaphore release 94.47 ns 43.62 ns 53.8%
Repeated permit debt 4.124 µs 1.731 µs 58.0%

@mhambre
mhambre marked this pull request as ready for review August 25, 2026 23:52

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@tisonkun
tisonkun enabled auto-merge (squash) August 26, 2026 00:00
@tisonkun
tisonkun merged commit 300618a into apache:main Aug 26, 2026
9 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.

2 participants