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

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.

@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 71.47%. Comparing base (cc5c81a) to head (90abd9d).

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%   71.47%   -0.05%     
===============================================
  Files              293      293              
  Lines            61928    61931       +3     
===============================================
- Hits             44289    44265      -24     
- Misses           17639    17666      +27     
Flag Coverage Δ
addons 92.38% <ø> (ø)
netcore 75.00% <81.81%> (-0.03%) ⬇️
netfx 69.87% <81.81%> (-0.04%) ⬇️

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
@priyankatiwari08
Copy link
Contributor

This branch needs a merge with main to include the codeql.yml file required for CodeQL scanning. The file should be placed under .github/workflows, which is currently missing in this branch. I had a similar experience for one of my PR where merge was blocked with similar code scanning comment, adding the file enabled successful code scanning.

Copilot AI review requested due to automatic review settings December 10, 2025 17:15
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 3 out of 3 changed files in this pull request and generated no new comments.

@cheenamalhotra cheenamalhotra force-pushed the dev/cheena/5.1-port-sqlstatisticsperf branch from 90abd9d to 86fba26 Compare December 11, 2025 18:24
paulmedynski
paulmedynski previously approved these changes Dec 11, 2025
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.

Comment on lines +23 to +24
var adpType = Assembly.GetAssembly(typeof(SqlConnection)).GetType("Microsoft.Data.Common.ADP", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
return (uint) adpType.GetMethod("CalculateTickCountElapsed", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).Invoke(null, new object[] {startTick, endTick});
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

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

The BindingFlags usage is overly verbose with full qualification. After adding the using System.Reflection; directive, change System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic to BindingFlags.Static | BindingFlags.NonPublic for consistency with other test files in this directory.

Copilot uses AI. Check for mistakes.
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

5 participants