Skip to content

avoid Lock acquisition on ErrorCount/WarningCount when no errors exist#4157

Open
SimonCropp wants to merge 3 commits intodotnet:mainfrom
SimonCropp:avoid-Lock-acquisition-on-ErrorCount/WarningCount-when-no-errors-exist
Open

avoid Lock acquisition on ErrorCount/WarningCount when no errors exist#4157
SimonCropp wants to merge 3 commits intodotnet:mainfrom
SimonCropp:avoid-Lock-acquisition-on-ErrorCount/WarningCount-when-no-errors-exist

Conversation

@SimonCropp
Copy link
Copy Markdown
Contributor

  1. _hasErrorOrWarning marked volatile (line 278) -- the field was already read without a lock at line 1212, so this makes the existing pattern and the new fast paths correct across all memory models.
  2. ErrorCount fast path -- returns 0 immediately when _hasErrorOrWarning is false, skipping the lock. Safe because _hasErrorOrWarning is only set to false under the lock when _errors is also nulled.
  3. WarningCount fast path -- same treatment.

  1. _hasErrorOrWarning marked volatile (line 278) -- the field was already read without a lock at line 1212, so this  makes the existing pattern and the new fast paths correct across all memory models.
  2. ErrorCount fast path -- returns 0 immediately when _hasErrorOrWarning is false, skipping the lock. Safe because  _hasErrorOrWarning is only set to false under the lock when _errors is also nulled.
  3. WarningCount fast path -- same treatment.
@github-project-automation github-project-automation bot moved this to To triage in SqlClient Board Apr 8, 2026
Copilot AI review requested due to automatic review settings April 8, 2026 02:58
@SimonCropp SimonCropp requested a review from a team as a code owner April 8, 2026 02:58
Copy link
Copy Markdown
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

This PR optimizes error/warning counting on TdsParserStateObject by adding a lock-free fast path when no errors/warnings are present, using a volatile flag to make the existing lock-free reads safe across memory models.

Changes:

  • Mark _hasErrorOrWarning as volatile to support safe lock-free reads.
  • Add early-return fast paths in ErrorCount and WarningCount when _hasErrorOrWarning is false.

…arserStateObject.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 8, 2026 03:17
…arserStateObject.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
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

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

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

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

2 participants