perf: replace KeyError exception with dict.get() in BoundStatement.bi…#755
perf: replace KeyError exception with dict.get() in BoundStatement.bi…#755mykaul wants to merge 1 commit intoscylladb:masterfrom
Conversation
…nd() Replace try/except KeyError with dict.get() + sentinel pattern in the per-column binding loop of BoundStatement.bind(). This loop runs once per column per execute() call for dict-style bindings, making it a hot path. Using dict.get() avoids the overhead of raising and catching KeyError for every missing/optional column. The sentinel object (_BIND_SENTINEL) is necessary to distinguish a missing key from an explicit None value in the bound dict.
There was a problem hiding this comment.
Pull request overview
Improves the performance of dict-style parameter binding in BoundStatement.bind() by avoiding KeyError exception handling in the per-column binding loop, which is on a hot path during execute() for prepared statements.
Changes:
- Introduces a private sentinel (
_BIND_SENTINEL) to distinguish “missing key” from an explicitNone. - Replaces
try/except KeyErrorwithdict.get(..., sentinel)in the dict-binding loop to avoid exception overhead.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Review of Copilot's CommentsComment 1: Module-level
|
…nd()
Replace try/except KeyError with dict.get() + sentinel pattern in the per-column binding loop of BoundStatement.bind(). This loop runs once per column per execute() call for dict-style bindings, making it a hot path. Using dict.get() avoids the overhead of raising and catching KeyError for every missing/optional column.
The sentinel object (_BIND_SENTINEL) is necessary to distinguish a missing key from an explicit None value in the bound dict.
Pre-review checklist
./docs/source/.Fixes:annotations to PR description.