Skip to content

Improve async string perf and fix reading chars with initial offset. #3377

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

Merged
merged 7 commits into from
Jun 4, 2025

Conversation

Wraith2
Copy link
Contributor

@Wraith2 Wraith2 commented May 26, 2025

Description

For performance related changes see background information in #3274 (comment) and the preceeding conversation. Reading a string in async mode was being slower than expected so I investigated. I will annotate each change with an explanation.

Issues

fixes #3331
fixes #3274

Testing

Tests have been added which cover both issues that are being fixed.

@Wraith2 Wraith2 requested a review from a team as a code owner May 26, 2025 20:26
@Wraith2
Copy link
Contributor Author

Wraith2 commented May 26, 2025

/cc @Tornhoof, @AlexanderKot this should fix your issues.

@dotnet/sqlclientdevteam can I get a CI kick? I'd really really like to get this in to preview 2 because it fixes all the known issues with async continue.

@cheenamalhotra
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 59.71%. Comparing base (b8948f2) to head (e8df89e).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
...nt/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs 0.00% 6 Missing ⚠️
.../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs 0.00% 5 Missing ⚠️
...c/Microsoft/Data/SqlClient/TdsParserStateObject.cs 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (b8948f2) and HEAD (e8df89e). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (b8948f2) HEAD (e8df89e)
addons 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3377      +/-   ##
==========================================
- Coverage   67.04%   59.71%   -7.33%     
==========================================
  Files         300      293       -7     
  Lines       65376    65308      -68     
==========================================
- Hits        43831    39000    -4831     
- Misses      21545    26308    +4763     
Flag Coverage Δ
addons ?
netcore 63.02% <0.00%> (-9.17%) ⬇️
netfx 61.03% <0.00%> (-4.15%) ⬇️

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 added this to the 6.1-preview2 milestone May 27, 2025
@cheenamalhotra cheenamalhotra requested a review from Copilot May 27, 2025 05:39
Copy link
Contributor

@Copilot 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 targets performance improvements in asynchronous string processing and corrects an issue with reading characters using an initial offset.

  • Added a new sequential character reading test ("CanGetCharsSequentially") to verify correct behavior.
  • Introduced helper methods in tests to use pooled buffers, ensuring buffers are resized appropriately.
  • Updated buffer management logic in TdsParser (both netfx and netcore) to use the correct offset and to improve buffer reallocation efficiency.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs Adds a new test and helper method for sequential character reading using pooled buffers.
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs Introduces a GetPacketSize() method and a property to calculate the current packet index.
src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs Adjusts buffer sizing logic and offset handling to improve performance and correctness.
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs Mirrors changes in netfx for improved buffer management and offset accumulation.

@cheenamalhotra cheenamalhotra requested a review from a team May 27, 2025 17:23
@cheenamalhotra
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

paulmedynski
paulmedynski previously approved these changes May 29, 2025
@mdaigle mdaigle self-assigned this May 29, 2025
Copy link
Contributor

@benrr101 benrr101 left a comment

Choose a reason for hiding this comment

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

I can't say I know much about the internals here, so I appreciate the callouts on what changes are being made. However, I'm not understanding what the _longlen changes are really doing. Please take a look at my comments and I'll approve if you can explain it without code changes :)

@paulmedynski
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@mdaigle
Copy link
Contributor

mdaigle commented Jun 3, 2025

@benrr101 this one needs an updated review from you

Copy link
Contributor

@benrr101 benrr101 left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes!

@mdaigle mdaigle merged commit 05df554 into dotnet:main Jun 4, 2025
237 checks passed
@Wraith2 Wraith2 deleted the fix-3274 branch June 5, 2025 23: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
6 participants