Skip to content

Commit 71da1b5

Browse files
committed
fast path
1 parent 79280df commit 71da1b5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/SignalR/server/Core/src/HubConnectionContext.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ public HubConnectionContext(ConnectionContext connectionContext, HubConnectionCo
7474
_systemClock = contextOptions.SystemClock ?? new SystemClock();
7575
_lastSendTimeStamp = _systemClock.UtcNowTicks;
7676

77-
var maxInvokes = contextOptions.MaximumParallelInvocations;
78-
ActiveInvocationLimit = new SemaphoreSlim(maxInvokes, maxInvokes);
77+
// We'll be avoiding using the semaphore when the limit is set to 1, so no need to allocate it
78+
var maxInvokeLimit = contextOptions.MaximumParallelInvocations;
79+
if (maxInvokeLimit != 1)
80+
{
81+
ActiveInvocationLimit = new SemaphoreSlim(maxInvokeLimit, maxInvokeLimit);
82+
}
7983
}
8084

8185
internal StreamTracker StreamTracker

src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private Task ProcessInvocation(HubConnectionContext connection,
259259
else
260260
{
261261
bool isStreamCall = descriptor.StreamingParameters != null;
262-
if (!isStreamCall && !isStreamResponse)
262+
if (connection.ActiveInvocationLimit != null && !isStreamCall && !isStreamResponse)
263263
{
264264
return connection.ActiveInvocationLimit.RunAsync(state =>
265265
{

0 commit comments

Comments
 (0)