Skip to content

Decode all LZ4 frames and enable Thrift CloudFetch compression - #643

Open
vuanhphung wants to merge 9 commits into
mainfrom
perf/thrift-lz4
Open

vuanhphung wants to merge 9 commits into
mainfrom
perf/thrift-lz4

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Thrift CloudFetch disables LZ4 after failures in the former codec. The current native decoder reads only the first concatenated frame and accepts truncated footers, so removing the guard alone silently loses rows; live files contain up to 613 frames. Walk and bound every frame, preserve checksum/error context, and let the existing Arrow converter detect missing rows without a second parse while retaining its excess-row cap.

This approved default change requests LZ4 for all supported Thrift Arrow results, inline and CloudFetch, when the codec loads. Client/per-statement useLZ4Compression: false still opts out; compression can change server-selected delivery to inline. Native kernel code is unchanged. Native async decoding was implemented and measured with the default libuv pool of 4, but raises RSS and the observed materialized tail. The selected allowed fallback yields between compressed files; decoding remains synchronous and loop stalls remain.

Per-file yields do not interleave concurrent streams: decodes queued together can run back-to-back in the same check phase. Five concurrent 1gb reads raise loop p99 about 2.9× in the reviewer's run (45.1→129.6 ms), and about 1.8× in our table (68.9→125.4 ms). Like existing CloudFetch download errors, decode failures remain non-sticky: catching one and resuming iteration can continue with later files, so that result is incomplete.

The shared converter now raises HiveDriverError with Arrow row count mismatch for previously silent short reads on every Arrow path/backend, including metadata, inline Thrift, uncompressed CloudFetch and kernel results; excess rows retain the existing cap.

Verification: 1,898 units, lint/Prettier/types/build, 31 live Thrift and 17 live kernel tests pass. All nine full ordered main/off/on checksums and lifecycle digests agree; three regression mutants fail. Across 123 final compressed queries / 11,594 files, no decode/checksum errors occur. CI passes Node 22/24/26; driver-test/kernel PR gates are stubs, not live passes.

Selected fallback, live Node 24.22.1, four CPUs, shared warehouse; five rotated fresh-process measurements per variant after warmup. Durations are median / p95=p99 (maximum at n=5); RSS is median process peak; loop is median per-run p99.

Scenario Main → yield median / p95 s RSS MiB main → yield Loop p99 ms main → yield
catalog_sales 100mb 1.848/2.507 → 1.394/1.452 541 → 329 17.0 → 21.8
500mb 5.359/6.978 → 3.399/3.626 586 → 368 18.3 → 20.8
1gb 9.465/16.269 → 5.427/5.821 801 → 543 20.7 → 32.8
4gb 66.357/97.848 → 28.153/30.139 1061 → 566 18.8 → 33.4
1gb materialized 38.165/40.005 → 37.375/38.120 1908 → 1273 510.4 → 486.5
Five concurrent 1gb 23.393/25.795 → 19.085/19.655 3710 → 1509 68.9 → 125.4
SELECT 1 .139/.149 → .142/.145 98 → 100 10.2 → 10.2
lineitem LIMIT 50k 1.033/1.338 → .941/1.087 125 → 143 11.0 → 10.7

Catalog_sales transfers 3.69× fewer bytes. Labels are selectivities: 1gb/4gb emit 2.109/13.864 GB. Materialized latency improves only 2.1%; its RSS falls 33%. Small reads can use more memory, including ~2–3 MiB to load the codec (nation rerun 97→100 MiB). Extended-type medians improve 10–28%, but the struct maximum is slightly worse. All rows/outliers and backend/A/A controls remain in factory evidence; the kernel's 5.6% median increase has a comparable 4.9% identical-build A/A shift. No zero-regression claim is inferred from noisy controls.

Rejected async candidate, separately interleaved with its own main controls, same hardware/pool and n=5. It improves responsiveness, but 500mb RSS reaches 1160 MiB and materialized p95 48.698s; the historical checksum failure and native-memory mechanism are not independently root-caused.

Scenario Main → async median / p95 s RSS MiB main → async Loop p99 ms main → async
100mb 1.868/2.228 → 1.299/1.395 549 → 582 20.6 → 21.4
500mb 5.862/7.195 → 3.213/3.475 603 → 1160 19.4 → 16.0
1gb 9.218/13.007 → 5.369/6.051 980 → 790 19.5 → 16.9
4gb 56.438/91.917 → 25.014/29.518 1062 → 923 19.5 → 18.6
1gb materialized 37.716/38.497 → 35.838/48.698 1658 → 1902 506.5 → 528.7
Five concurrent 1gb 24.304/26.357 → 11.471/14.646 3611 → 2163 69.7 → 59.9

Adversarial review: converged in round 2 with no open high findings; all follow-ups resolved or accepted with the concurrent-loop and non-sticky-error limitations disclosed above.

This pull request and its description were written by Isaac.

Bound every frame before decoding, preserve CloudFetch frame buffers, and validate decoded row counts before exposing results.

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>
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 marked this pull request as ready for review November 20, 2026 14:09

@peco-review-bot peco-review-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 was successfully deployed

1 active deployment
azure-prod — 7296802d Deployed Nov 20, 2026 by vuanhphung via e2e-test (22.23.4, 22_23_4) #2200
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