Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

SqlClient memory performance changes #32811

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
304 changes: 173 additions & 131 deletions src/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.IO;
using System.Globalization;
using System.Security;
using System.Runtime.CompilerServices;

namespace System.Data.SqlClient
{
Expand Down Expand Up @@ -911,7 +912,7 @@ internal Task ValidateAndReconnect(Action beforeDisconnect, int timeout)
catch (SqlException)
{
}
runningReconnect = Task.Run(() => ReconnectAsync(timeout));
runningReconnect = ValidateAndReconnectSetupReconnectContinuation(timeout);
// if current reconnect is not null, somebody already started reconnection task - some kind of race condition
Debug.Assert(_currentReconnectionTask == null, "Duplicate reconnection tasks detected");
_currentReconnectionTask = runningReconnect;
Expand Down Expand Up @@ -949,6 +950,13 @@ internal Task ValidateAndReconnect(Action beforeDisconnect, int timeout)
return runningReconnect;
}

// This is in its own method to avoid always allocating the lambda in ValidateAndReconnect
[MethodImpl(MethodImplOptions.NoInlining)]
private Task ValidateAndReconnectSetupReconnectContinuation(int timeout)
{
return Task.Run(() => ReconnectAsync(timeout));
}

// this is straightforward, but expensive method to do connection resiliency - it take locks and all preparations as for TDS request
partial void RepairInnerConnection()
{
Expand Down
Loading