Skip to content

remove duplicate dictionary lookups#4000

Open
SimonCropp wants to merge 1 commit intodotnet:mainfrom
SimonCropp:remove-duplicate-dictionary-lookups
Open

remove duplicate dictionary lookups#4000
SimonCropp wants to merge 1 commit intodotnet:mainfrom
SimonCropp:remove-duplicate-dictionary-lookups

Conversation

@SimonCropp
Copy link
Contributor

@SimonCropp SimonCropp commented Mar 5, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 5, 2026 00:22
@SimonCropp SimonCropp requested a review from a team as a code owner March 5, 2026 00:22
@github-project-automation github-project-automation bot moved this to To triage in SqlClient Board Mar 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors several internal dictionary access patterns to avoid redundant ContainsKey + indexer lookups, primarily by switching to TryGetValue (and, for the DNS cache, direct indexer assignment) while preserving existing behavior in SqlDependency-related infrastructure.

Changes:

  • Replace double-lookups with TryGetValue in SqlDependency* code paths.
  • Simplify DNS cache insertion to a single overwrite assignment.
  • Update server enumerator parsing to use TryGetValue for instance detail extraction.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.cs Uses TryGetValue for dependency ID lookup under lock.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyListener.cs Replaces repeated dictionary lookups with TryGetValue in app-domain/container tracking paths.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs Uses TryGetValue to avoid multiple lookups in server/user hash management and default options composition.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SQLFallbackDNSCache.cs Simplifies add/replace semantics to a single assignment into the ConcurrentDictionary.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorManagedHelper.netcore.cs Uses TryGetValue when populating DataRow fields from parsed instance details.

@paulmedynski
Copy link
Contributor

/azp run

@paulmedynski paulmedynski self-assigned this Mar 5, 2026
@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Contributor

@paulmedynski paulmedynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A glorious set of changes! 🚀 Just a couple of comments.

@github-project-automation github-project-automation bot moved this from To triage to In progress in SqlClient Board Mar 5, 2026
@paulmedynski paulmedynski added this to the 7.0.1 milestone Mar 9, 2026
@paulmedynski paulmedynski added the Code Health 💊 Issues/PRs that are targeted to source code quality improvements. label Mar 9, 2026
@paulmedynski paulmedynski modified the milestones: 7.0.1, 7.1.0-preview1 Mar 11, 2026
@mdaigle
Copy link
Contributor

mdaigle commented Mar 23, 2026

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Health 💊 Issues/PRs that are targeted to source code quality improvements.

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

4 participants