Skip to content

Conversation

@cheenamalhotra
Copy link
Member

Ports #3609 to release/5.1 branch

Closes #3763

Copilot AI review requested due to automatic review settings December 5, 2025 20:18
@cheenamalhotra cheenamalhotra requested a review from a team as a code owner December 5, 2025 20:18
@cheenamalhotra cheenamalhotra added this to the 5.1.9 milestone Dec 5, 2025
@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 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

…apsedTest.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings December 5, 2025 20:24
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

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

Copilot AI review requested due to automatic review settings December 5, 2025 21:03
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

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);
Copy link

Copilot AI Dec 5, 2025

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);

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.76%. Comparing base (cc5c81a) to head (1f4edde).

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/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     
Flag Coverage Δ
addons 92.38% <ø> (ø)
netcore 75.00% <81.81%> (-0.03%) ⬇️
netfx 68.78% <81.81%> (-1.14%) ⬇️

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.

Copy link
Contributor

@paulmedynski paulmedynski left a 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.

@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 v5.1

4 participants