Skip to content

Conversation

@gargsaumya
Copy link
Contributor

Work Item / Issue Reference

AB#<WORK_ITEM_ID>

GitHub Issue: #<ISSUE_NUMBER>


Summary

This pull request introduces several performance and maintainability improvements to the MSSQL Python driver, focusing on optimizing row creation, reducing repeated lookups of Python types and settings, and ensuring proper cursor configuration. The changes span both the Python and C++ layers, with new caching mechanisms and more efficient resource usage.

Python-side row creation optimizations

  • Added caching for column name maps, converter maps, and settings snapshots in the Cursor class to avoid repeated computation during row fetching. These caches are now built and reused for all fetch operations (fetchone, fetchmany, fetchall). [1] [2]
  • Updated row creation logic to use these cached optimizations, resulting in more efficient instantiation of Row objects. [1] [2] [3]

C++/pybind11 Python type caching

  • Introduced a PythonObjectCache namespace in ddbc_bindings.cpp to cache references to Python classes (datetime, date, time, decimal, uuid). This reduces overhead and avoids issues during Python finalization. All type checks and conversions now use the cached objects. [1] [2] [3] [4] [5] [6] [7]

Cursor configuration and resource management

  • Changed statement execution in C++ to use forward-only cursors instead of static cursors, improving compatibility and performance for result set traversal. [1] [2]
  • Ensured __exit__ in the Python Cursor class consistently returns None for proper context manager behavior.

Miscellaneous improvements

  • Improved error handling and result set initialization in the Python execute method, ensuring column metadata is properly described and available for optimizations.
  • Cached the decimal separator in the C++ data retrieval logic to minimize repeated system calls when parsing numeric data.

@github-actions github-actions bot added the pr-size: large Substantial code update label Oct 30, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: large Substantial code update labels Oct 31, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Oct 31, 2025
@gargsaumya
Copy link
Contributor Author

This is not needed anymore, perf PR is merged. Closing this draft.

@gargsaumya gargsaumya closed this Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: large Substantial code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants