Repository navigation
perf(pyo3): avoid runtime entry for buffered fetch and drained close - #477
Conversation
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 High · 1 Low
Looks good, with 1 low concern. The nonblocking fast path matches the kernel's try_next_batch auto-close-on-drain behavior, and the C ABI already calls this read outside a runtime. Skipping close() after exhaustion is safe because the closed flag is already set.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Terra added findings it doesn't mention — see the findings below.
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good, with one low-severity concern. Skipping close on an exhausted handle does the same thing as before: the kernel's try_next_batch End path already schedules the close and finalizes telemetry, and close_server_statement short-circuits once closed is set. Moving the CloudFetch log calls out from under the locks looks correct.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Terra added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit — The tests check results and cleanup only, so they would still pass if every read went back through the runtime. Instrument runtime entries or GIL handoffs if the fast path needs a regression guard. (Found by GPT-6.1 Terra · confirmed by the judge)
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, no findings. Skipping close once the handle is exhausted is safe because the drain path already finalizes telemetry and claims the closed flag. The try-lock probes in CloudFetch keep batch order and cursor accounting intact on retry, and the log calls now run with no locks held.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Terra added findings it doesn't mention — see the findings below.
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Nit
Looks good — 1 low concern. EOF from the nonblocking read still schedules the statement close and finalizes telemetry (executed.rs:175, result_stream.rs:721), and the CloudFetch nonblocking reads keep chunk order and accounting correct when a lock is busy.
Other findings
- ⚪ Nit — The PyO3 binding now returns
InvalidStatefor a non-Arrow ResultBatch variant, but napi/src/statement.rs:367 still usesKernelError::invalid_argument()(the async path does the same), so the two bindings report different error codes. The case is unreachable in practice. Align the codes, or note why they differ. (Found by Claude Opus 5.5 · confirmed by the judge)
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Share Arrow extraction for buffered, waiting, and draining reads. Exercise both refresh skip logs with callbacks that require a writable chunk shard. Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Use nonblocking buffer, shard and terminal-error lock attempts so Python can wait with the GIL released. Cover contended reads and runtime bypass through the real Python result handles. Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Continue the waiting fetch path past empty chunks and check EOF at the current cursor. Exercise the probe-to-wait handoff, delayed empty-chunk continuation, GIL release, and result cleanup before parent closure. Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Reuse the owned batch-read result and one local HTTP fixture across native and Python tests. Retain the existing unsupported-format error category and preserve earlier chunks before later link-fetch errors. Keep bounded contention and lifecycle checks while removing the redundant callback harness. Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
Python result fetching enters Tokio and releases/reacquires the GIL even when a batch is already buffered.
Before: Every
fetch_next_batch()call enters the runtime, including buffered data and EOF. Closing a drained executed handle enters it again after exhaustion has already finalized telemetry and scheduled cleanup.After: Both Python result handles probe for an available batch first. Buffered data and EOF return directly. Pending reads retain the wait with the GIL released; drained close retains runtime release and skips the completed kernel close operation.
CloudFetch uses nonblocking buffer, shard and error-lock attempts, returning
Pendingon contention. The waiting path skips empty chunks, and both paths deliver earlier chunks before a later link-fetch error. Shared guards are released before logging, including for uncached loggers that can acquire the GIL before filtering. Batch order, accounting, terminal errors and statement DELETE cleanup are preserved. Unsupported formats retainInvalidArgumentacross Python fetch/drain paths, matching Node.One buffered batch, EOF and drained close avoid three runtime entries and GIL release/reacquire pairs while the session remains open and provider locks are available. Isolated end-to-end throughput gain is unmeasured. Buffered batches requiring column rewrites perform that synchronous work with the GIL held.
Validation
Pending, ordered recovery and accounting. Binding tests verify runtime bypass and that waiting releases the GIL; restoring unconditional runtime entry in either real handle fails its guard.The native binding and Python tests share one local HTTP fixture.