Skip to content

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

Merged
vuanhphung merged 16 commits into
mainfrom
perf/try-next
Dec 1, 2026
Merged

vuanhphung merged 16 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).

Test-review follow-up: fixture teardown waits for the statement DELETE, idle TLS connections, and 20ms without newly accepted connections before shutdown. The earlier local SIGPIPEs came from the fixture, not native code. Before main's #581 required a newer bindings release, published v1.5.0 passed 24/24 stability processes on a4417b9 and ten full-suite runs on aecafa9; c8113e4 also passed 24/24 with the quiet guard. Plain main independently fails to link the published archive's missing kernel_session_config_set_port symbol. The merged head retains main's header/pin unchanged; source pin 3b691d2 passes make test-kernel and 24/24 stability processes with zero closed-socket handshake errors. #581's binding compatibility is outside this PR.

Adversarial review: converged after two rounds; accepted test fixes are 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.

Use the source-built kernel SIGPIPE fix merged in #606 instead of ignoring SIGPIPE process-wide in the kernel tests.

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.

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>
@vuanhphung
vuanhphung marked this pull request as draft November 30, 2026 23:24
vuanhphung and others added 2 commits December 1, 2026 00:08
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 marked this pull request as ready for review December 1, 2026 01:06
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 issues. In nextBatch, the call to try_next_batch only falls back to the blocking next_batch on Success with ready=false. That fallback stays inside the same call() wrapper, so eviction and error wrapping still apply. The pinned header declares the symbol, and the new E2E test matches the nightly TestKernelE2E filter.

Other findings

  • ⚪ Nit — The CloudFetch test relies on a fixed 20ms sleep and a loose blockingFetches <= chunks/2 bound to wait for chunks to be decoded, so it is timing-sensitive on slow CI. Poll for decode readiness, or expose a hook that signals when the prefetch buffer is full. (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>

@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

Copy link
Copy Markdown
Collaborator Author

Fixed the readiness nit in 1d4d333. CloudFetch now polls the real try path with a 5s bound; the existing nil-in-production test hook can decline blocking fallback and report Pending. The decode sleep/count tolerance is removed; all eight chunks, values and EOF remain asserted. The source-pin matrix passes 24/24, 24-way race stress passes 1,920/1,920 with zero blocking fetches, and mutants a/b/c fail assertions. The separate TLS accept-quiet guard remains.


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).

✅ No issues identified.

@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
vuanhphung enabled auto-merge December 1, 2026 06:25
@vuanhphung
vuanhphung added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 2175155 Dec 1, 2026
14 checks passed
@vuanhphung
vuanhphung deleted the perf/try-next branch December 1, 2026 06:37
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.

2 participants