-
Notifications
You must be signed in to change notification settings - Fork 317
[5.1] Optimization: Use Environment.TickCount for SqlStatistics execution timing #3831
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
base: release/5.1
Are you sure you want to change the base?
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 SQL execution timing statistics by replacing the DateTime-based timer with Environment.TickCount for measuring ExecutionTime. This change reduces overhead while maintaining accuracy for performance statistics. The PR ports optimization work from #3609 to the release/5.1 branch.
Key changes:
- Replaced DateTime.UtcNow.ToFileTimeUtc() with Environment.TickCount for ExecutionTime measurements
- Added wraparound-safe elapsed time calculation to handle TickCount rolling over every ~24.9 days
- Removed unreliable timing comparison assertions that could fail due to timing precision differences
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| AdapterUtil.cs | Added FastTimerCurrent() to return Environment.TickCount and CalculateTickCountElapsed() to calculate elapsed time with wraparound handling |
| SqlStatistics.cs | Changed _startExecutionTimestamp to nullable long, updated ExecutionTime accumulation to use TickCount directly (already in milliseconds), removed TimerToMilliseconds conversion |
| TickCountElapsedTest.cs | New test file validating wraparound handling for TickCount elapsed time calculations |
| Microsoft.Data.SqlClient.Tests.csproj | Registered the new TickCountElapsedTest.cs test file |
| CopyAllFromReader.cs | Removed assertions comparing ConnectionTime/ExecutionTime/NetworkServerTime as these are no longer reliable with different timing mechanisms |
src/Microsoft.Data.SqlClient/tests/FunctionalTests/TickCountElapsedTest.cs
Outdated
Show resolved
Hide resolved
…apsedTest.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
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
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
| /// </summary> | ||
| public sealed class TickCountElapsedTest | ||
| { | ||
| internal static uint CalculateTickCountElapsed(long startTick, long endTick) => (uint)(endTick - startTick); |
Copilot
AI
Dec 5, 2025
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.
The test is duplicating the implementation logic instead of testing the actual ADP.CalculateTickCountElapsed method. This test should call ADP.CalculateTickCountElapsed directly to validate the real implementation, not a copy of it. Consider changing this to:
internal static uint CalculateTickCountElapsed(long startTick, long endTick) => ADP.CalculateTickCountElapsed(startTick, endTick);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.
Agreed.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/5.1 #3831 +/- ##
===============================================
- Coverage 71.51% 70.76% -0.75%
===============================================
Files 293 293
Lines 61928 61931 +3
===============================================
- Hits 44289 43828 -461
- Misses 17639 18103 +464
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:
|
paulmedynski
left a comment
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.
I agree with Copilot.
Ports #3609 to release/5.1 branch
Closes #3763