PERF: Optimize checked temporal fetch construction - #795
Draft
Jahnvi Thakkar (jahnvi480) wants to merge 1 commit into
Draft
Jahnvi Thakkar (jahnvi480) wants to merge 1 commit into
Jahnvi Thakkar (jahnvi480) wants to merge 1 commit into
Conversation
Use direct CPython date/time/datetime construction for exact cached standard types, preserving substituted constructors and exception behavior. Cover row-wise and batch fetch contracts in isolated subprocesses. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Jahnvi Thakkar (jahnvi480)
September 17, 2026 14:27
View session
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Native extension changes span multiple fetch paths, with limited platform and validation coverage.
Pull request overview
Optimizes native SQL temporal fetch construction while preserving custom constructors and conversion behavior.
Changes:
- Adds checked datetime construction helpers.
- Integrates them into six temporal fetch paths.
- Adds regression tests and changelog documentation.
File summaries
| File | Reviewed changes |
|---|---|
tests/test_038_fetch_temporal.py |
Temporal parity, constructor, exception, and fetch API coverage |
mssql_python/pybind/fetch_temporal.hpp |
Translation-unit-local checked construction helpers |
mssql_python/pybind/ddbc_bindings.cpp |
Integration into row-wise and batch temporal fetch paths |
CHANGELOG.md |
Documents the optimization and preserved behavior |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
mssql_python/pybind/ddbc_bindings.cppLines 4443-4452 4443 }
4444 case SQL_SS_TIME2: {
4445 const SQL_SS_TIME2_STRUCT& t2 = buffers.timeBuffers[col - 1][i];
4446 py::object timeObj =
! 4447 FetchTemporal::time(t2.hour, t2.minute, t2.second, t2.fraction / 1000);
! 4448 PyList_SET_ITEM(row, col - 1, timeObj.release().ptr());
4449 break;
4450 }
4451 case SQL_SS_TIMESTAMPOFFSET: {
4452 SQLULEN rowIdx = i;mssql_python/pybind/fetch_temporal.hppLines 13-23 13
14 // datetime.h keeps PyDateTimeAPI per translation unit, so these helpers must too.
15 static inline void ensure_datetime_api() {
16 if (PyDateTimeAPI == nullptr) {
! 17 PyDateTime_IMPORT;
! 18 if (PyDateTimeAPI == nullptr) throw py::error_already_set();
! 19 }
20 }
21
22 static inline py::object date(int year, int month, int day) {
23 ensure_datetime_api();📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.performance_counter.hpp: 0.7%
mssql_python.pybind.logger_bridge.cpp: 57.9%
mssql_python.pybind.ddbc_bindings.h: 61.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.row.py: 77.6%
mssql_python.pybind.ddbc_bindings.cpp: 77.9%
mssql_python.pybind.connection.connection_pool.cpp: 81.8%
mssql_python.logging.py: 86.2%
mssql_python.pooling.py: 90.1%
mssql_python.cursor.py: 92.1%🔗 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.
Work Item / Issue Reference
Summary
Reduce per-value Python-call overhead when converting fetched SQL DATE, TIME, and TIMESTAMP values into Python objects. This draft is for cross-platform build/test validation, not a claim of universal performance improvement or merge readiness.
fetch_temporal.hpphelpers using checkedPyDate_FromDate,PyTime_FromTime, andPyDateTime_FromDateAndTimeonly for the exact standard cached constructor identities.Local validation
Windows x64, CPython 3.13.15, pybind11 3.0.1, MSVC Release with profiling compiled out; SQL Server 15.0.4382.1 and ODBC 18.6.2.1.
Performance observations and limitations
Matched uninstrumented baseline/candidate measurements used 12 paired rounds with nine samples per case, retaining all ordered samples. One predeclared confirmation was run after noisy calibration. These figures describe this actual temporal-only source, not an integrated optimization branch.
The 15-case confirmation sum of fetch medians decreased 531.062 -> 506.612 ms (4.60%); execute-plus-drain decreased 543.121 -> 518.142 ms (4.60%). These are sums of fixed workload medians, not an application speedup. Separate pure TIME/TIMESTAMP cases also produced positive observations, but are not added to these percentages.
Identical-build A/A calibration was very noisy (paired score interval 0.828x to 1.951x). Negative unchanged confirmation controls are retained: narrow fetchone -1.19%, many(1) -1.14%, fetchall -2.79%, converter many -4.63%, converter all -2.39%; their intervals span zero. No dependable blanket no-regression conclusion is established.
Retained validation limitations