Repository navigation
perf(napi): pack ready result batches into fewer IPC payloads - #489
vuanhphung wants to merge 11 commits into
Conversation
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>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, with one low concern. Packing is bounded. Lookahead errors and EOF stay deferred until a normal fetch returns them, telemetry finalization is idempotent, and auto-close still fires only on a normal drain.
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good: 2 low concerns. The packing caps, deferring of lookahead errors/EOF, and auto-close/telemetry ordering all check out. Tests cover the EOF, early-close and download-failure paths.
Other findings
- ⚪ Nit — The rustdoc and changelog call this "lookahead", but a
Readyresult installs the batch ascurrentand resets the row cursor, so it consumes the batch. Only errors and end-of-stream are deferred. State in the rustdoc and changelog thatReadyadvances the stream. (Found by Claude Opus 5.5 · confirmed by the judge)
…cement Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
|
Fixed the review-body nit in 61fad38: the public rustdoc now explicitly says Ready advances the stream, replaces current and resets the row cursor; the changelog also says Ready advances. Only errors and end-of-stream stay deferred. |
There was a problem hiding this comment.
🔀 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. Ready-only lookahead keeps errors and end-of-stream for the next normal fetch, so close and telemetry still happen once. The size caps never underflow, and dictionary schemas are correctly left unpacked. The only note is a nit about naming the row and message caps as constants.
Other findings
- ⚪ Nit — The row cap (16_384, which is repeated in
16_384 - rows) and the message cap (16) are inline literals inIpcStream::next, but the byte cap is the named constantIPC_TARGET_BYTES. Add constants such asIPC_TARGET_ROWSandIPC_MAX_MESSAGESso each limit has one definition. (Found by Claude Opus 5.5 · confirmed by the judge)
|
Reviewed the cap-naming nit on 61fad38. Both 16,384-row literals agree, and boundary tests pin that limit and the 16-message limit, including empty and oversized batches. These are fixed internal limits; there is no current mismatch or steady-state behavior/performance issue. I am retaining the current spelling for this optimization and leaving the naming cleanup out of scope. |
Resolve the main changes by merging (no force-push). Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 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, with one low-severity concern about a test assertion. Ready-only lookahead never finalizes telemetry or marks the stream exhausted, and errors are buffered and replayed on the next normal fetch. Finalization is idempotent through the finalized guard. Nit: the 16,384-row and 16-message caps are inline literals, unlike IPC_TARGET_BYTES.
Other findings
- ⚪ Nit — The failed-download test accepts either
NetworkErrororInternalas a substring of the reason, so it would pass if the deferred error carried the wrong code. Parse the envelope first and assert the exact expectedcode. (Found by Claude Opus 5.5 · confirmed by the judge)
80M BOOLEAN rows make 19,533 napi calls, each repeating IPC schema decoding, promise handling and reader setup. Packing ready batches reduces that to 4,884 calls and cuts live BOOLEAN/FLOAT/DOUBLE total time by 50.4%/33.2%/22.1% on four cores.
Write already-ready batches into one IPC stream, preserving original record-batch boundaries, with caps of 16,384 rows, 1MiB sliced Arrow data (excluding IPC framing), and 16 messages. Single oversized batches pass through; dictionary schemas never pack because apache-arrow 13 ignores replacements. No additional download is awaited; speculative errors/EOF wait for ordinary fetches. Output reservation includes framing and oversized batches. No flag is needed: results/types/nulls/user chunks and configuration defaults stay identical, grouping is bounded, and deployment requires a driver release that bumps its exact 1.4.0 binding pin and runs kernel e2e. CloudFetch scheduling is unchanged.
Verification: 106 napi tests plus the explicit ignored fixture exporter pass; root/napi clippy and formatting pass. Five new mutants fail loudly, including reservation and metadata-wrapper coverage; Node kernel e2e: 34 pass/four OAuth pending. Eight ordered SHA-256/chunk cases match main; the reviewed build also matched seven full-result fingerprints/schemas/null counts. Five fresh rotated/interleaved pairs after warm-up, window 16; seconds, median/p95 (p99=p95=max):
The 1MiB cap leaves essentially one wide batch per payload and removes the earlier materialization slowdown. Final materialized 100MB is 17.793→17.023s; A/A is 17.574→17.368s. The requested 2MiB candidate regressed 4.97% and was rejected. Final replay uses production 37b8879; subsequent commits change tests/docs only, with production logic identity recorded. The clean BOOLEAN repeat excludes checkpoint-compression overlap; all original observations remain in the handoff.
Accepted trade-off: about 2–3MiB more peak JS heap per concurrent materialized narrow reader, bounded by 16,384 rows. For five × 80M-row readers the V8 heap OOM threshold moves from roughly 96–112MB to 112–128MB; RSS is unchanged. Early close can count at most one extra result batch and one extra CloudFetch chunk in telemetry; full drains are unaffected.
No 1GB drain/total-time gain is claimed; drain changes sit inside A/A variation. User CPU: 4.321→4.466s / 4.831→5.021s (four/eight cores). Reviewed five-reader 4GB RSS: 3062→2792MiB, one observation each; ready-close median/p95: 34.7/109.0→72.9/95.4ms, ready-cancel p95: 67.1→100.5ms, stalled close/cancel p95≤116.7ms, zero ERROR logs. Full retained runs/stage tails and exact reviewer harness are in the handoff. All final-head CI checks pass except the pre-existing chrono@0.4.45/RUSTSEC-2026-0543 Security Scan failure in unchanged lockfiles.
Adversarial review: converged in round 3 with no open high; heap trade-off accepted, reservation/docs follow-ups fixed, bot approved and inline findings addressed.
This pull request and its description were written by Isaac.