-
Notifications
You must be signed in to change notification settings - Fork 317
[6.1] Optimization: Use Environment.TickCount for SqlStatistics execution timing #3830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.1] Optimization: Use Environment.TickCount for SqlStatistics execution timing #3830
Conversation
There was a problem hiding this 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
_startExecutionTimestampfromlongtolong?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 |
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlStatistics.cs
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…eena/6.1-port-sqlstatisticsperf
Ports #3609 to release/6.1
Closes #3762