ProcessMessages takes cs_main for every peer on every handler pass, just to check for orphan transactions to reconsider, though most peers have none. This PR checks for orphan work under m_tx_download_mutex first and skips cs_main when there is none. Peers with orphan work take the same path as before, plus one uncontended lock.
This removes needless cs_main contention with validation, RPC and wallet threads. It's part of a broader effort to reduce cs_main contention in net processing (see #36244 for context), but stands on its own.
ProcessMessages handling a ping |
master | this PR |
|---|---|---|
| no contention | 0.005 ms | 0.005 ms |
another thread holds cs_main for 50 ms |
50.1 ms | 0.02 ms |
Release builds, median of 3 runs. SendMessages in the same handler pass still takes cs_main.
Tested by process_messages_without_orphan_work, which fails without this change.