Skip to content

remove duplicate dictionary lookups - #4000

Merged
mdaigle merged 1 commit into
dotnet:mainfrom
SimonCropp:remove-duplicate-dictionary-lookups
Mar 25, 2026
Merged

mdaigle merged 1 commit into
dotnet:mainfrom
SimonCropp:remove-duplicate-dictionary-lookups

Conversation

@SimonCropp

@SimonCropp SimonCropp commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

/azp run

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

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@paulmedynski paulmedynski left a comment

Copy link
Copy Markdown
Contributor

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

mdaigle commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@codecov

codecov Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.61905% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.49%. Comparing base (3303d80) to head (c9900e2).
⚠️ Report is 42 commits behind head on main.

Files with missing lines Patch % Lines
...ql/SqlDataSourceEnumeratorManagedHelper.netcore.cs 0.00% 8 Missing ⚠️
.../Microsoft/Data/SqlClient/SqlDependencyListener.cs 77.77% 2 Missing ⚠️
...src/Microsoft/Data/SqlClient/SqlDependencyUtils.cs 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (3303d80) and HEAD (c9900e2). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (3303d80) HEAD (c9900e2)
CI-SqlClient 2 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4000      +/-   ##
==========================================
- Coverage   74.38%   65.49%   -8.90%     
==========================================
  Files         287      275      -12     
  Lines       43982    65805   +21823     
==========================================
+ Hits        32717    43097   +10380     
- Misses      11265    22708   +11443     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 65.49% <47.61%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mdaigle mdaigle modified the milestone: 7.1.0-preview1 Mar 25, 2026
@mdaigle
mdaigle merged commit ab95f6f into dotnet:main Mar 25, 2026
304 of 306 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in SqlClient Board Mar 25, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

4 participants