You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use an Atomic that can be accessed without holding the mutex.
On the fastpath, where the role is already set this returns much more quickly.
On the slowpath we still acquire the mutex and update the value as we did before,
although we read the atomic value again to check whether we've raced with another thread that has updated it meanwhile already.
Before (measuring both unloaded, and loaded situation where other threads are accessing the mutex):
```
Running benchmarks (no workloads)
╭────────────────────────────────────┬───────────────────────────┬───────────────────────────┬───────────────────────────╮
│name │ major-allocated │ minor-allocated │ monotonic-clock │
├────────────────────────────────────┼───────────────────────────┼───────────────────────────┼───────────────────────────┤
│ Cached reads/Pool_role.is_master │ 0.0000 mjw/run│ 4.0000 mnw/run│ 23.6039 ns/run│
╰────────────────────────────────────┴───────────────────────────┴───────────────────────────┴───────────────────────────╯
Cached reads/Pool_role.is_master (ns):
{ monotonic-clock per run = 23.603889 (confidence: 23.644693 to 23.568067);
r² = Some 0.999899 }
Running benchmarks (workloads)
╭────────────────────────────────────┬───────────────────────────┬───────────────────────────┬───────────────────────────╮
│name │ major-allocated │ minor-allocated │ monotonic-clock │
├────────────────────────────────────┼───────────────────────────┼───────────────────────────┼───────────────────────────┤
│ Cached reads/Pool_role.is_master │ 0.0000 mjw/run│ 7.4201 mnw/run│ 76.4067 ns/run│
╰────────────────────────────────────┴───────────────────────────┴───────────────────────────┴───────────────────────────╯
Cached reads/Pool_role.is_master (ns):
{ monotonic-clock per run = 76.406674 (confidence: 86.718075 to 66.336404);
r² = Some 0.608131 }
```
After:
```
Running benchmarks (no workloads)
╭────────────────────────────────────┬───────────────────────────┬───────────────────────────┬───────────────────────────╮
│name │ major-allocated │ minor-allocated │ monotonic-clock │
├────────────────────────────────────┼───────────────────────────┼───────────────────────────┼───────────────────────────┤
│ Cached reads/Pool_role.is_master │ 0.0000 mjw/run│ 0.0000 mnw/run│ 3.1256 ns/run│
╰────────────────────────────────────┴───────────────────────────┴───────────────────────────┴───────────────────────────╯
Cached reads/Pool_role.is_master (ns):
{ monotonic-clock per run = 3.125616 (confidence: 3.131412 to 3.120373);
r² = Some 0.999885 }
Running benchmarks (workloads)
╭────────────────────────────────────┬───────────────────────────┬───────────────────────────┬───────────────────────────╮
│name │ major-allocated │ minor-allocated │ monotonic-clock │
├────────────────────────────────────┼───────────────────────────┼───────────────────────────┼───────────────────────────┤
│ Cached reads/Pool_role.is_master │ 0.0000 mjw/run│ 0.0000 mnw/run│ 6.2872 ns/run│
╰────────────────────────────────────┴───────────────────────────┴───────────────────────────┴───────────────────────────╯
Cached reads/Pool_role.is_master (ns):
{ monotonic-clock per run = 6.287197 (confidence: 6.737363 to 5.830140);
r² = Some 0.706843 }
```
Signed-off-by: Edwin Török <[email protected]>
0 commit comments