Skip to content

Reduce IsAzureSynapseOnDemandEndpoint allocations #3363

Open
@vonzshik

Description

@vonzshik

Every time you create a new instance of SqlConnection, if the connection string's RetryCount is equal to 1 (which is the default value) SqlClient will attempt to subtly replace it with 5 if it determines that the host is azure synapse on demand endpoint.

_connectRetryCount = connString.ConnectRetryCount;
// For Azure Synapse ondemand connections, set _connectRetryCount to 5 instead of 1 to greatly improve recovery
// success rate. Note: Synapse should be detected first as it could be detected as a regular Azure SQL DB endpoint.
if (_connectRetryCount == 1 && ADP.IsAzureSynapseOnDemandEndpoint(connString.DataSource))
{
_connectRetryCount = 5;
}

The problem is that to determine that SqlClient concats prefix -ondemand with a collection of specific endpoints and then checks whether the host contains any endpoint. With 5 endpoints, that's 5 string allocations per each instance of SqlConnection, which in a simple benchmark results in about 40% of total allocations.

// check if servername ends with any endpoints
for (int index = 0; index < s_azureSqlServerEndpoints.Length; index++)
{
string endpoint = string.IsNullOrEmpty(prefix) ? s_azureSqlServerEndpoints[index] : prefix + s_azureSqlServerEndpoints[index];
if (length > endpoint.Length)
{
if (string.Compare(dataSource, length - endpoint.Length, endpoint, 0, endpoint.Length, StringComparison.OrdinalIgnoreCase) == 0)
{
return true;
}
}
}

Image

Maybe it's better to instantiate them once just like it's done for azure sql server endpoints?

Metadata

Metadata

Assignees

Labels

Triage Done ✔️Issues that are triaged by dev team and are in investigation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions