Skip to content

Conversation

@cheenamalhotra
Copy link
Member

Ports #3609 to release/6.1

Closes #3762

@cheenamalhotra cheenamalhotra added this to the 6.1.4 milestone Dec 5, 2025
@cheenamalhotra cheenamalhotra requested a review from a team as a code owner December 5, 2025 20:14
Copilot AI review requested due to automatic review settings December 5, 2025 20:14
@cheenamalhotra cheenamalhotra linked an issue Dec 5, 2025 that may be closed by this pull request
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

This PR optimizes the SqlStatistics execution timing mechanism by replacing the high-precision DateTime.UtcNow timer with the more efficient Environment.TickCount for measuring execution time. This change improves performance while maintaining millisecond precision for the ExecutionTime statistic. The PR is a port of #3609 to the release/6.1 branch.

Key Changes

  • Introduced Environment.TickCount-based timing for ExecutionTime measurements with proper wraparound handling
  • Changed _startExecutionTimestamp from long to long? to distinguish between "not started" (null) and "started" states
  • Removed timing relationship assertions that can no longer be guaranteed due to different timer granularities

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs Added FastTimerCurrent() and CalculateTickCountElapsed() helper methods for Environment.TickCount-based timing
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlStatistics.cs Updated ExecutionTime tracking to use Environment.TickCount, changed _startExecutionTimestamp to nullable long, and removed TimerToMilliseconds conversion for ExecutionTime
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/TickCountElapsedTest.cs Added comprehensive unit tests for wraparound scenarios in TickCount elapsed time calculations
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader.cs Removed timing relationship assertions that cannot be guaranteed with mixed timer types

@paulmedynski paulmedynski self-assigned this Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backport SqlStatistics perf improvement to MDS v6.1

4 participants