Skip to content

Commit

Permalink
Reduce SyncStatusList lock contention
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed May 4, 2023
1 parent 2c1da7a commit df320a9
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@ public void GetInfosForBatch(BlockInfo?[] blockInfos)
switch (_statuses[currentNumber])
{
case FastBlockStatus.Unknown:
blockInfos[collected] = _blockTree.FindCanonicalBlockInfo(currentNumber);
BlockInfo? blockInfo = null;
// Release the lock while performing the longer storage operation
// to reduce lock contention
Monitor.Exit(_statuses);
try
{
blockInfo = _blockTree.FindCanonicalBlockInfo(currentNumber);
}
finally
{
// Re-enter the lock
Monitor.Enter(_statuses);
}
blockInfos[collected] = blockInfo;
_statuses[currentNumber] = FastBlockStatus.Sent;
collected++;
break;
Expand Down

0 comments on commit df320a9

Please sign in to comment.