Commit c8f4db2
committed
perf: skip lock acquisition when no orphaned requests in process_msg
Check orphaned_request_ids truthiness before acquiring the lock. Since
orphaned requests are rare (only on timeouts), the set is almost always
empty. Skipping the lock in the common case saves ~57 ns per response.
The unlocked truthiness check on a set is thread-safe under the GIL.
Worst case (false positive): we enter the lock block and re-check, which
is correct. Worst case (false negative): an orphaned response is
processed normally — acceptable behavior.
Benchmark (2M iters, Python 3.14):
Empty set (common): 80.6 -> 23.2 ns (3.47x, -57.4 ns/response)
Non-empty set (rare): 79.7 -> 87.8 ns (+8.1 ns overhead)1 parent fb4ee4d commit c8f4db2
1 file changed
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1395 | 1395 | | |
1396 | 1396 | | |
1397 | 1397 | | |
1398 | | - | |
1399 | | - | |
1400 | | - | |
1401 | | - | |
1402 | | - | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
1403 | 1409 | | |
1404 | 1410 | | |
1405 | 1411 | | |
| |||
0 commit comments