Skip to content

Add BatchSemaphore::close_no_scheduling_point#227

Merged
jorajeev merged 1 commit intomainfrom
nosp
Nov 17, 2025
Merged

Add BatchSemaphore::close_no_scheduling_point#227
jorajeev merged 1 commit intomainfrom
nosp

Conversation

@sarsko
Copy link
Contributor

@sarsko sarsko commented Nov 4, 2025

Adds BatchSemaphore::close_no_scheduling_point.

The reason for adding this is that primitives which utilize multiple semaphores (in my case: mpsc) need to be able to close more than one semaphore without having more than one scheduling point. This is both for efficiency, and for not leaving a system which is partially closed.

The latter could have been solved with an atomic field as the source of truth on whether the system is closed or not, but I prefer exposing this method as this approach is more efficient than having needless scheduling points.

There is however one con of this, which is that after #212 gets merged, a switch becomes both a scheduling point and an "indicator of interest". If this PR gets merged, then any users of BatchSemaphore::close_no_scheduling_point will not indicate any interest on those BatchSemaphores. There's a couple potential solutions to this that come to mind:

  1. Ignore it
  2. Add a new Event which takes multiple Events. The code would then never use close, and instead do a single switch before calling close_no_scheduling_point on whichever BatchSemaphores it wants to close.

There might be a case to expose multiple _no_scheduling_point functions. My stance is that we'll add those once we need them. If it becomes the case that we want multiple _no_scheduling_point functions, then I will probably suggest to refactor the code such that switch(Event) returns a Switched(Event) which would be passed by ownership to the _no_scheduling_point functions in order to make sure that a scheduling point has occurred and that a corresponding Event has been created. Again, that bridge is to be burned if that river is ever to be crossed.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Benchmark for 0855531

Click to view benchmark
Test Base PR %
buffer/pct 75.8±0.49ms 75.1±1.01ms -0.92%
buffer/random 104.6±0.27ms 105.2±1.84ms +0.57%
counter async/pct-narrow 1110.7±28.48µs 1117.1±31.74µs +0.58%
counter async/pct-wide 11.0±0.09ms 11.0±0.08ms 0.00%
counter async/random-narrow 1404.5±17.02µs 1387.1±17.97µs -1.24%
counter async/random-wide 4.3±0.06ms 4.3±0.06ms 0.00%
counter scaling async/RW/{tasks:1024,events:100000} 77.6±0.72ms 76.7±0.47ms -1.16%
counter scaling async/RW/{tasks:128,events:100000} 37.6±0.11ms 37.5±0.28ms -0.27%
counter scaling async/RW/{tasks:128,events:10000} 4.8±0.05ms 4.8±0.05ms 0.00%
counter scaling async/RW/{tasks:16,events:100000} 17.8±0.05ms 17.5±0.03ms -1.69%
counter scaling async/RW/{tasks:16,events:10000} 2.0±0.01ms 1986.3±19.80µs -0.69%
counter scaling async/RW/{tasks:16,events:1000} 441.2±9.48µs 425.2±5.75µs -3.63%
counter scaling async/RW/{tasks:32,events:100000} 21.0±0.09ms 20.8±0.12ms -0.95%
counter scaling async/RW/{tasks:32,events:10000} 2.5±0.02ms 2.5±0.01ms 0.00%
counter scaling async/RW/{tasks:32,events:1000} 711.2±12.27µs 696.3±10.40µs -2.10%
counter scaling async/RW/{tasks:4,events:100000} 13.1±0.03ms 12.8±0.03ms -2.29%
counter scaling async/RW/{tasks:4,events:10000} 1384.2±3.08µs 1361.7±3.81µs -1.63%
counter scaling async/RW/{tasks:4,events:1000} 201.5±2.60µs 204.5±2.42µs +1.49%
counter scaling async/RW/{tasks:64,events:100000} 27.3±0.74ms 27.0±0.04ms -1.10%
counter scaling async/RW/{tasks:64,events:10000} 3.5±0.02ms 3.5±0.02ms 0.00%
counter scaling async/RW/{tasks:64,events:1000} 1219.8±30.99µs 1235.5±23.16µs +1.29%
counter sync/pct-narrow 1106.3±18.19µs 1106.9±22.92µs +0.05%
counter sync/pct-wide 11.0±0.07ms 11.0±0.07ms 0.00%
counter sync/random-narrow 1413.8±9.44µs 1392.9±8.00µs -1.48%
counter sync/random-wide 4.3±0.07ms 4.4±0.06ms +2.33%
create async/pct-narrow 880.9±8.13µs 873.1±9.20µs -0.89%
create async/pct-wide 29.0±0.17ms 28.8±0.12ms -0.69%
create async/random-narrow 847.1±12.41µs 843.9±12.72µs -0.38%
create async/random-wide 16.9±0.22ms 16.8±0.09ms -0.59%
create sync/pct-narrow 918.7±9.55µs 915.1±10.20µs -0.39%
create sync/pct-wide 30.0±0.12ms 29.5±0.10ms -1.67%
create sync/random-narrow 860.3±9.54µs 858.0±7.83µs -0.27%
create sync/random-wide 18.7±0.44ms 18.1±0.07ms -3.21%
lock scaling sync/RW/{tasks:1024,events:100000} 15.8±0.06s 15.7±0.07s -0.63%
lock scaling sync/RW/{tasks:128,events:100000} 2.1±0.01s 2.1±0.01s 0.00%
lock scaling sync/RW/{tasks:128,events:10000} 199.2±0.16ms 198.1±0.61ms -0.55%
lock scaling sync/RW/{tasks:16,events:100000} 293.5±0.24ms 294.1±1.59ms +0.20%
lock scaling sync/RW/{tasks:16,events:10000} 29.3±0.05ms 29.4±0.08ms +0.34%
lock scaling sync/RW/{tasks:16,events:1000} 3.0±0.10ms 3.0±0.01ms 0.00%
lock scaling sync/RW/{tasks:32,events:100000} 553.4±9.87ms 549.1±2.44ms -0.78%
lock scaling sync/RW/{tasks:32,events:10000} 54.4±0.10ms 54.2±0.07ms -0.37%
lock scaling sync/RW/{tasks:32,events:1000} 5.5±0.02ms 5.5±0.02ms 0.00%
lock scaling sync/RW/{tasks:4,events:100000} 88.8±0.34ms 90.0±0.14ms +1.35%
lock scaling sync/RW/{tasks:4,events:10000} 8.9±0.02ms 9.0±0.02ms +1.12%
lock scaling sync/RW/{tasks:4,events:1000} 952.7±2.83µs 963.4±3.72µs +1.12%
lock scaling sync/RW/{tasks:64,events:100000} 1059.8±1.48ms 1051.9±2.27ms -0.75%
lock scaling sync/RW/{tasks:64,events:10000} 103.8±0.73ms 102.7±0.11ms -1.06%
lock scaling sync/RW/{tasks:64,events:1000} 9.7±0.03ms 9.6±0.04ms -1.03%
lock sync/pct-narrow 3.1±0.19ms 3.1±0.02ms 0.00%
lock sync/pct-wide 21.9±0.56ms 22.2±0.18ms +1.37%
lock sync/random-narrow 10.8±0.05ms 11.0±0.04ms +1.85%
lock sync/random-wide 158.6±0.33ms 157.0±0.75ms -1.01%

@github-actions
Copy link

Benchmark for 1c8dfda

Click to view benchmark
Test Base PR %
buffer/pct 75.4±1.51ms 76.0±0.85ms +0.80%
buffer/random 104.4±1.05ms 104.8±1.13ms +0.38%
counter async/pct-narrow 1108.0±25.13µs 1110.2±27.17µs +0.20%
counter async/pct-wide 11.0±0.19ms 10.9±0.16ms -0.91%
counter async/random-narrow 1370.9±39.90µs 1430.2±24.14µs +4.33%
counter async/random-wide 4.2±0.07ms 4.3±0.07ms +2.38%
counter scaling async/RW/{tasks:1024,events:100000} 76.8±0.72ms 76.1±0.87ms -0.91%
counter scaling async/RW/{tasks:128,events:100000} 36.0±0.35ms 36.3±0.20ms +0.83%
counter scaling async/RW/{tasks:128,events:10000} 4.7±0.05ms 4.7±0.05ms 0.00%
counter scaling async/RW/{tasks:16,events:100000} 17.1±0.15ms 17.9±0.06ms +4.68%
counter scaling async/RW/{tasks:16,events:10000} 1944.7±19.25µs 2.0±0.03ms +2.84%
counter scaling async/RW/{tasks:16,events:1000} 432.1±7.42µs 435.9±6.29µs +0.88%
counter scaling async/RW/{tasks:32,events:100000} 20.8±0.39ms 21.2±0.30ms +1.92%
counter scaling async/RW/{tasks:32,events:10000} 2.5±0.02ms 2.5±0.02ms 0.00%
counter scaling async/RW/{tasks:32,events:1000} 700.8±13.05µs 692.2±12.88µs -1.23%
counter scaling async/RW/{tasks:4,events:100000} 12.8±0.02ms 13.3±0.05ms +3.91%
counter scaling async/RW/{tasks:4,events:10000} 1350.8±6.81µs 1396.1±15.66µs +3.35%
counter scaling async/RW/{tasks:4,events:1000} 198.8±2.19µs 200.0±2.43µs +0.60%
counter scaling async/RW/{tasks:64,events:100000} 26.5±0.26ms 27.0±0.11ms +1.89%
counter scaling async/RW/{tasks:64,events:10000} 3.4±0.04ms 3.5±0.04ms +2.94%
counter scaling async/RW/{tasks:64,events:1000} 1211.1±21.97µs 1207.4±23.07µs -0.31%
counter sync/pct-narrow 1106.4±17.48µs 1099.7±22.02µs -0.61%
counter sync/pct-wide 11.0±0.16ms 11.0±0.08ms 0.00%
counter sync/random-narrow 1383.9±12.45µs 1441.5±24.70µs +4.16%
counter sync/random-wide 4.2±0.09ms 4.3±0.06ms +2.38%
create async/pct-narrow 885.4±12.53µs 862.3±13.34µs -2.61%
create async/pct-wide 28.7±0.47ms 28.4±0.42ms -1.05%
create async/random-narrow 839.4±8.59µs 828.3±10.69µs -1.32%
create async/random-wide 16.7±0.14ms 16.7±0.15ms 0.00%
create sync/pct-narrow 921.5±6.96µs 894.4±19.45µs -2.94%
create sync/pct-wide 29.8±0.35ms 29.5±0.27ms -1.01%
create sync/random-narrow 849.6±9.74µs 851.3±10.96µs +0.20%
create sync/random-wide 17.8±0.23ms 18.1±0.07ms +1.69%
lock scaling sync/RW/{tasks:1024,events:100000} 16.0±0.06s 16.2±0.06s +1.25%
lock scaling sync/RW/{tasks:128,events:100000} 2.1±0.01s 2.1±0.01s 0.00%
lock scaling sync/RW/{tasks:128,events:10000} 199.6±0.75ms 198.3±2.07ms -0.65%
lock scaling sync/RW/{tasks:16,events:100000} 292.5±2.08ms 293.9±0.43ms +0.48%
lock scaling sync/RW/{tasks:16,events:10000} 29.3±0.15ms 29.3±0.03ms 0.00%
lock scaling sync/RW/{tasks:16,events:1000} 3.0±0.01ms 3.0±0.01ms 0.00%
lock scaling sync/RW/{tasks:32,events:100000} 549.4±5.17ms 551.5±1.16ms +0.38%
lock scaling sync/RW/{tasks:32,events:10000} 54.4±0.26ms 54.4±0.08ms 0.00%
lock scaling sync/RW/{tasks:32,events:1000} 5.5±0.07ms 5.5±0.01ms 0.00%
lock scaling sync/RW/{tasks:4,events:100000} 89.1±0.33ms 88.1±0.07ms -1.12%
lock scaling sync/RW/{tasks:4,events:10000} 8.9±0.06ms 8.8±0.02ms -1.12%
lock scaling sync/RW/{tasks:4,events:1000} 956.2±7.22µs 948.1±8.13µs -0.85%
lock scaling sync/RW/{tasks:64,events:100000} 1057.3±5.53ms 1058.4±5.78ms +0.10%
lock scaling sync/RW/{tasks:64,events:10000} 103.5±0.88ms 103.7±0.07ms +0.19%
lock scaling sync/RW/{tasks:64,events:1000} 9.7±0.08ms 9.7±0.03ms 0.00%
lock sync/pct-narrow 3.0±0.04ms 3.1±0.02ms +3.33%
lock sync/pct-wide 21.7±0.16ms 21.4±0.14ms -1.38%
lock sync/random-narrow 10.9±0.04ms 10.8±0.04ms -0.92%
lock sync/random-wide 158.1±0.95ms 158.1±0.49ms 0.00%

@jorajeev jorajeev merged commit 42cba21 into main Nov 17, 2025
7 checks passed
@sarsko sarsko deleted the nosp branch November 26, 2025 09:24
@sarsko sarsko mentioned this pull request Jan 12, 2026
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