Skip to content

perf(kernel): read buffered result batches without a runtime hop - #600

Open
vuanhphung wants to merge 8 commits into
mainfrom
perf/try-next
Open

vuanhphung wants to merge 8 commits into
mainfrom
perf/try-next

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

The kernel result path used a blocking runtime hop even when an Arrow batch was buffered. The boolean profile attributes .27s of 5.37s CPU samples to nextBatch. Avoiding the hop cuts an 80M-row boolean scan (19,533 batches) by 11.8% live, versus 0.8% A/A drift. The buffered-batch benchmark saves ~28.5µs/batch, predicting ~.56s against the 6.79s main query.

Try the non-blocking API first and block only when it reports pending. Both calls retain the existing thread-local error wrapper, eviction, cancellation, Arrow ownership, logging and telemetry. Kernel only; Thrift is untouched. Overlap: #599 adds a separate reset in nextBatch; #514 changes the Arrow IPC surface.

Verification: default/tagged unit suites, 20 native race repetitions, live result/lifecycle tests, typed row-count/multiset checksums, and default lint. Extra tagged-lint/generated-format findings match main. Live query+drain seconds use eight fresh processes per side, rotated ABBA, warmups excluded; p95=p99 at this sample size:

Scenario Main median / p95 Branch median / p95
Boolean 80M 6.791 / 7.122 5.992 / 6.443
Float 50M 6.847 / 7.501 6.361 / 7.272
Double 30M, first 5.545 / 6.058 5.788 / 9.245
Double repeat 5.462 / 7.326 5.240 / 5.907
Inline LIMIT10000 .2845 / .3268 .2783 / .3936
Catalog sales 500MB 6.349 / 6.911 5.931 / 6.830
SELECT 1 .1507 / .1616 .1415 / .1537

Boolean user/system CPU medians: 5.175/.280s → 4.800/.045s. Double is inconclusive; tiny/wide-query percentage changes are not attributable to this patch (one batch saves tens of µs; 1,132 wide batches predict ~32ms).

Adversarial review: converged after two takeover rounds; requested test fixes verified, with no open high findings.

This pull request and its description were written by Isaac.

vuanhphung and others added 4 commits November 27, 2026 04:28
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@vuanhphung vuanhphung changed the title Read buffered kernel result batches without a runtime hop perf(kernel): read buffered result batches without a runtime hop Nov 27, 2026
@vuanhphung
vuanhphung marked this pull request as ready for review November 27, 2026 05:48

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

vuanhphung and others added 2 commits November 27, 2026 20:15
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Nit

Looks good, no blocking concerns. The header says try_next_batch leaves the Arrow outputs untouched while the batch is pending, so the fallback is safe, and error eviction and cancellation are unchanged. The new E2E test is already picked up by the nightly TestKernelE2E prefix filter.

Other findings

  • ⚪ Nit — The kernelRows type doc (and the "next_batch does the per-batch network/decode work" line) names only kernel_result_stream_next_batch. nextBatch now tries kernel_result_stream_try_next_batch first and uses next_batch only as the blocking fallback. Update the comment to say so. (Found by Claude Opus 5.5 · confirmed by the judge)

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@vuanhphung

Copy link
Copy Markdown
Collaborator Author

Fixed the documentation nit in 207423b: the kernelRows type comment now names kernel_result_stream_try_next_batch first and kernel_result_stream_next_batch only as the blocking fallback; the batch/row explanation now describes batch imports.


This comment was generated with GitHub MCP.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Nit

Looks good, no blocking findings. The non-blocking-first nextBatch keeps the existing error, eviction, EOF and import handling, and the tests cover the buffered, pending, error, cancel and close-during-fallback paths. I couldn't confirm that the pinned v1.5.0 bindings header exports try_next_batch, because the header isn't vendored here.

Other findings

  • ⚪ Nit — TestKernelRowsTryNextError asserts the kernel's native message text ('try_next_batch: pointers must not be null'), so the test is tied to that upstream wording. Asserting only the code and the kernel: next_batch wrapper would make it less brittle. (Found by Claude Opus 5.5 · the judge disputed it but couldn't back that up, so it's kept)

@vuanhphung

Copy link
Copy Markdown
Collaborator Author

Keeping the native-message assertion intentionally: it was requested to distinguish the two C APIs. Both return InvalidArgument and the same kernel: next_batch wrapper for a nil stream. Against the pinned v1.5.0 bindings, restoring main's blocking-only nextBatch fails this assertion with kernel_result_stream_next_batch: stream must not be null; checking only the code/wrapper would let that mutant pass. The kernel-tagged build and full tagged suite also pass against v1.5.0, confirming the try-next symbol resolves. A future wording change should update this test without losing the API distinction.


This comment was generated with GitHub MCP.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant