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
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.47%. Comparing base (de0195e) to head (1d8d747).
⚠️ Report is 1 commits behind head on release/6.1.

Files with missing lines Patch % Lines
...ient/src/Microsoft/Data/SqlClient/SqlStatistics.cs 77.77% 2 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           release/6.1    #3830       +/-   ##
================================================
- Coverage        90.82%   68.47%   -22.35%     
================================================
  Files                6      279      +273     
  Lines              316    53293    +52977     
================================================
+ Hits               287    36492    +36205     
- Misses              29    16801    +16772     
Flag Coverage Δ
addons 90.82% <ø> (ø)
netcore 72.63% <81.81%> (?)
netfx 69.13% <81.81%> (?)

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.

@cheenamalhotra cheenamalhotra merged commit 8291391 into release/6.1 Dec 10, 2025
252 checks passed
@cheenamalhotra cheenamalhotra deleted the dev/cheena/6.1-port-sqlstatisticsperf branch December 10, 2025 17:18
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

5 participants