Commit 78bcfbb
committed
perf(pool): eliminate mutex overhead in state machine hot path
The state machine was calling notifyWaiters() on EVERY Get/Put operation,
which acquired a mutex even when no waiters were present (the common case).
Fix: Use atomic waiterCount to check for waiters BEFORE acquiring mutex.
This eliminates mutex contention in the hot path (Get/Put operations).
Implementation:
- Added atomic.Int32 waiterCount field to ConnStateMachine
- Increment when adding waiter, decrement when removing
- Check waiterCount atomically before acquiring mutex in notifyWaiters()
Performance impact:
- Before: mutex lock/unlock on every Get/Put (even with no waiters)
- After: lock-free atomic check, only acquire mutex if waiters exist
- Expected improvement: ~30-50% for Get/Put operations1 parent 1b0168d commit 78bcfbb
1 file changed
+15
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
219 | 220 | | |
220 | 221 | | |
221 | 222 | | |
| 223 | + | |
222 | 224 | | |
223 | 225 | | |
224 | 226 | | |
| |||
227 | 229 | | |
228 | 230 | | |
229 | 231 | | |
| 232 | + | |
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
233 | 236 | | |
| 237 | + | |
234 | 238 | | |
235 | 239 | | |
236 | 240 | | |
237 | 241 | | |
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
241 | 251 | | |
242 | 252 | | |
243 | 253 | | |
| 254 | + | |
244 | 255 | | |
245 | 256 | | |
246 | 257 | | |
| |||
261 | 272 | | |
262 | 273 | | |
263 | 274 | | |
| 275 | + | |
264 | 276 | | |
265 | 277 | | |
266 | 278 | | |
| |||
273 | 285 | | |
274 | 286 | | |
275 | 287 | | |
| 288 | + | |
276 | 289 | | |
277 | 290 | | |
278 | 291 | | |
| |||
0 commit comments