Improve decoder throughput with buffered scalar reads - #299
Draft
Saurabh Singh (saurabh500) wants to merge 1 commit into
Draft
Improve decoder throughput with buffered scalar reads#299Saurabh Singh (saurabh500) wants to merge 1 commit into
Saurabh Singh (saurabh500) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Saurabh Singh (saurabh500)
August 15, 2026 00:44
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes TDS row decoding by synchronously consuming buffered scalar values while retaining the existing asynchronous packet-refill fallback.
Changes:
- Adds optional scalar probes to
TdsPacketReader. - Implements buffered byte,
u16, andi32reads forNetworkTransport. - Routes decoder hot paths through sync-first reads and adds boundary tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
mssql-tds/src/io/packet_reader.rs |
Defines non-consuming scalar probe methods. |
mssql-tds/src/datatypes/decoder.rs |
Uses sync-first scalar reads in decoder paths. |
mssql-tds/src/connection/transport/network_transport.rs |
Delegates probes and retains packet-refill fallback. |
mssql-tds/src/connection/transport/buffers.rs |
Implements scalar probes and unit tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
🔗 Quick Links |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Improves row-decoder throughput by reading buffered byte, little-endian
u16, and little-endiani32values synchronously fromNetworkTransport. A buffer miss falls back to the existing async TDS packet read/refill path and retries, so packet framing and error handling remain authoritative.This is a standalone runtime optimization informed by measurements from #269. It does not revive that PR or retry decoder convergence.
Implementation
TdsPacketReaderconfigurations, with safeNonedefaults for other readers.TdsReadBufferand delegates them fromNetworkTransport.read_tds_packet()as the only refill path for async misses.Correctness coverage
Targeted tests cover complete buffered reads, zero consumption when a scalar is incomplete, and
u16/i32values split across real TDS packet boundaries throughNetworkTransport. Existing NULL and length-marker handling remains unchanged.Production-reader benchmark
Compared clean
mainatac1023a1with this change using concreteNetworkTransport, packetized in-memory input, and 7,992-byte packet payloads. Each cell decoded 30,000 rows per pass with 2 warmups and 9 measured passes, across 8 paired rounds alternating baseline/candidate order. Negative deltas are faster.The INT/VARCHAR discard cell is noisy, and one mixed-materialize round regressed, but all paired medians improved and the materialized/mixed results are consistently strong. Builds used the same
Cargo.lockhash and isolated target directories; the resulting binaries had different SHA-256 hashes, ruling out accidental artifact reuse.Validation
cargo bfmtcargo bclippycargo nextest run -p mssql-tds --lib -E 'not test(/certificate_validator|win_tls::validate/)'(1,730 passed; fixture-dependent TLS tests excluded)$env:RUSTFLAGS='--cfg fuzzing'; cargo check -p mssql-tds --libcargo btestwas attempted locally but is not green in this environment: live SQL Server/TLS tests fail with SchannelSEC_E_WRONG_PRINCIPAL, and generated local certificate fixtures are absent. The corresponding remote validation is green.Risk
The fast path is limited to already-buffered scalars on
NetworkTransport. Other packet readers retain their existing async behavior through defaultNoneprobes. Misses preserve partial bytes and reuse the existing refill path, including cancellation and encryption behavior.Related Issues
Related to #247.
Historical measurement context: #269.
Checklist
cargo bfmtpassescargo bclippypassescargo btestpasses locally (environment-blocked; remote PR validation passes)