Skip to content

feat(parquet): bound input prefetch with a row-group window - #604

Open
SteNicholas wants to merge 1 commit into
apache:mainfrom
SteNicholas:PAIMON-602
Open

SteNicholas wants to merge 1 commit into
apache:mainfrom
SteNicholas:PAIMON-602

Conversation

@SteNicholas

@SteNicholas SteNicholas commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Purpose

Linked issue: close #602

Bound Parquet input pre-buffering in Paimon C++ with a sliding row-group window, aligned with Velox's prefetchRowGroups scheduling. Previously, Arrow could buffer projected input for every selected row group before returning the first batch, causing compressed input memory to grow with wide scans.

  • Prefetch projected column chunks and selected pages in a sliding window covering the current row group and up to parquet.read.cache-option.prefetch-row-groups subsequent row groups (default 1; 0 disables lookahead).
  • Apply parquet.read.cache-option.window-size-limit (default 128 MiB; 0 disables the window) when deciding whether to prefetch subsequent groups, counting coalesced gaps and in-flight reads while still prefetching at least the current row group when enabled.
  • Reuse buffered input on seeks within the window, retire consumed groups after their final batch, and drain submitted reads before releasing buffers from consumed or discarded groups.
  • Fall back to on-demand reads after prefetch failures and preserve row-group and page pruning, file row IDs, batch order, and returned Arrow batch lifetimes.

Benchmarks (Release)

Before-and-after comparison on a simulated HDD-backed DFS async stream (12 ms seek/RPC latency, 150 MiB/s shared bandwidth, 8 async I/O threads) across row-group sizes:

Case Mode 1st Batch (ms) Total (ms) Throughput (MiB/s) Peak Input (MiB) Async I/O
4MiB_x32RG before (Arrow full pre_buffer) 227.1 881.9 145.3 128.1 5
4MiB_x32RG after (128MiB, prefetch=0) 50.3 1489.5 86.0 4.0 32
4MiB_x32RG after (128MiB, prefetch=1, default) 49.4 873.6 146.6 8.0 32
4MiB_x32RG after (128MiB, prefetch=4) 49.9 871.6 147.0 20.0 32
32MiB_x8RG before (Arrow full pre_buffer) 248.1 1746.9 146.7 256.2 16
32MiB_x8RG after (128MiB, prefetch=1, default) 238.7 1742.4 147.0 64.0 16
128MiB_x3RG before (Arrow full pre_buffer) 904.3 2607.5 147.4 384.3 6
128MiB_x3RG after (128MiB, prefetch=1, default) 916.3 2722.3 141.2 128.1 6
160MiB_x2RG before (Arrow full pre_buffer) 1127.7 2195.7 145.8 320.2 4
160MiB_x2RG after (128MiB, prefetch=1, default) 1094.5 2239.9 143.0 160.1 4

Tests

  • Wide-string scan tests for bounded input memory as row-group count grows, file row IDs, batch order, and returned batch lifetimes.
  • Configurable lookahead tests (prefetch-row-groups = 0, 1, 3, negative rejection, byte-budget cap, and window-size-limit = 0 disabling prefetch) and end-to-end ParquetReaderBuilder option validation and async read count checks.
  • Oversized current row-group tests covering prefetching without lookahead, range coalescing, lookahead resumption after retirement, and seeking directly onto a cached oversized plan.
  • Seek, retirement, coalesced-gap, in-flight read, early close, prefetch failure fallback, and page-pruning tests across default, disabled, and undersized budgets.

API and Format

  • Add parquet.read.cache-option.window-size-limit in bytes (default 128 MiB; 0 disables the window).
  • Add parquet.read.cache-option.prefetch-row-groups for subsequent row groups to prefetch beyond the current one (default 1; 0 disables lookahead).
  • No change to the Parquet file format.

Documentation

Yes. Updated docs/source/user_guide/prefetch.rst to document the sliding row-group window, byte budget, lookahead option, lazy reads, and interaction with the shared read-ahead cache.

Generative AI tooling

Generated-by: Google Antigravity (Gemini 4)

@SteNicholas SteNicholas changed the title feat(parquet): bound prefetch with a row-group sliding window feat(parquet): bound input prefetch with a row-group window Nov 30, 2026
@lxy-9602
lxy-9602 requested a review from lucasfang December 1, 2026 07:29
@lucasfang

Copy link
Copy Markdown
Member

Could we make the number of subsequent row groups to prefetch configurable, instead of hardcoding a limit of 64? This would align with Velox’s prefetchRowGroups semantics: default to 1 additional row group beyond the current one, with 0 meaning no lookahead.

@lucasfang

Copy link
Copy Markdown
Member

Could we also add before-and-after performance benchmarks on slower storage, such as an HDD-backed distributed file system, to verify that the reduced prefetch window does not cause a significant performance regression? It would be useful to compare scan throughput and first-batch latency across different row-group sizes.

@lucasfang

Copy link
Copy Markdown
Member

Could we consider increasing the default prefetch budget to 128 MiB? Also, could we allow at least the current row group to be prefetched even if it exceeds the budget, and apply the budget when deciding whether to prefetch subsequent groups? Increasing the default alone would still leave larger row groups falling back to on-demand reads.

Arrow could pre-buffer every selected row group before returning the
first batch, letting compressed input memory grow with wide scans.
Issue apache#602 calls for bounding Parquet input pre-buffering with a
sliding row-group window.

- Prefetch projected column chunks and selected pages in a sliding
  window covering the current row group and configurable lookahead via
  parquet.read.cache-option.prefetch-row-groups (default 1, 0 disables
  lookahead).
- Apply parquet.read.cache-option.window-size-limit (default 128 MiB,
  0 disables the window) to subsequent lookahead, counting coalesced
  gaps and in-flight reads while still prefetching at least the
  current row group when enabled.
- Reuse buffered input on seeks within the window, retire consumed
  groups after their final batch and drain submitted reads before
  releasing buffers from consumed or discarded groups.
- Fall back to on-demand reads after prefetch failures and preserve
  row-group and page pruning, file row IDs, batch order and returned
  Arrow batch lifetimes.
- Cover bounded wide-string scans, lookahead limits, oversized current
  groups, coalesced gaps, seeks, early close and prefetch failures.
  Document the window options and lifecycle behavior.
@SteNicholas

Copy link
Copy Markdown
Member Author

Thanks @lucasfang for the thorough review! I have updated the PR (commit 7333df0f) to address all three comments:

  1. Configurable lookahead row groups (#issuecomment-7305126650):

    • Replaced the hardcoded 64 limit with parquet.read.cache-option.prefetch-row-groups, matching Velox's prefetchRowGroups semantics: defaults to 1 additional row group beyond the current one, with 0 disabling lookahead while still prefetching the current row group (negative values are rejected).
    • Added unit and end-to-end ParquetReaderBuilder tests covering 0, 1, 2, 3, negative rejection, and byte-budget capping when prefetch-row-groups is larger, and updated docs/source/user_guide/prefetch.rst.
  2. 128 MiB default budget & prefetching the current row group (#issuecomment-7306341085):

    • Increased the default parquet.read.cache-option.window-size-limit from 64 MiB to 128 MiB (aligned with Paimon's default 128 MiB row-group size and Velox's kDefaultCoalesceBytes).
    • When window-size-limit > 0, at least the current row group is always prefetched (with range coalescing preserved) even if it exceeds the budget, and the budget is applied when deciding whether to prefetch subsequent groups. Setting window-size-limit = 0 or parquet.read.enable-pre-buffer = false still disables pre-buffering completely.
    • Added tests for oversized current row groups (both full and page-filtered), range coalescing on oversized groups, lookahead resumption after retirement, and seeking directly onto a cached oversized plan.
  3. Slow-storage before-and-after benchmarks (#issuecomment-7306159294):

    • Added a Release before-and-after comparison to the PR description using a simulated HDD-backed DFS async stream (12 ms seek/RPC latency, 150 MiB/s shared bandwidth, 8 async I/O threads) across 4 MiB, 32 MiB, 128 MiB, and 160 MiB row groups:
Case Mode 1st Batch (ms) Total (ms) Throughput (MiB/s) Peak Input (MiB) Async I/O
4MiB_x32RG before (Arrow full pre_buffer) 227.1 881.9 145.3 128.1 5
4MiB_x32RG after (128MiB, prefetch=0) 50.3 1489.5 86.0 4.0 32
4MiB_x32RG after (128MiB, prefetch=1, default) 49.4 873.6 146.6 8.0 32
4MiB_x32RG after (128MiB, prefetch=4) 49.9 871.6 147.0 20.0 32
32MiB_x8RG before (Arrow full pre_buffer) 248.1 1746.9 146.7 256.2 16
32MiB_x8RG after (128MiB, prefetch=1, default) 238.7 1742.4 147.0 64.0 16
128MiB_x3RG before (Arrow full pre_buffer) 904.3 2607.5 147.4 384.3 6
128MiB_x3RG after (128MiB, prefetch=1, default) 916.3 2722.3 141.2 128.1 6
160MiB_x2RG before (Arrow full pre_buffer) 1127.7 2195.7 145.8 320.2 4
160MiB_x2RG after (128MiB, prefetch=1, default) 1094.5 2239.9 143.0 160.1 4
  • With the new defaults (128 MiB, prefetch-row-groups = 1), 4 MiB and 32 MiB row groups match full pre-buffer throughput while cutting first-batch latency (4.6x faster on 4 MiB) and peak input memory (4x–16x lower), and 128 MiB / 160 MiB row groups stay within ~2–4% of baseline throughput without falling back to uncoalesced on-demand reads while cutting peak input memory 2x–3x. (Note: these numbers are from a simulated slow-storage stream locally; happy to supplement with real HDD DFS cluster measurements as well if needed.)

@lucasfang
lucasfang requested a review from lxy-9602 December 3, 2026 07:32
@lxy-9602

lxy-9602 commented Dec 4, 2026

Copy link
Copy Markdown
Member

@zjw1111 Please run the Parquet read performance regression again for this pr (test both with prefetch enabled and disabled). Thanks!

@lxy-9602

lxy-9602 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Also, it looks like #598 has only one patch left. @SteNicholas How about merging it first (it already went through full review and performance regression), and then rebasing the current PR? I noticed both changes have modified the Arrow patch.

}
} else {
// No overlap, add as new range
merged.push_back(curr);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the previous comment was fine—why did we remove it this time?

///
/// This exercises the full path: ComputePageRanges → PreBufferRanges → CachedInputStream →
/// ReadFilteredRowGroup with page_ranges.
TEST_F(PageFilteredRowGroupReaderTest, EndToEndPageLevelPreBuffer) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you clarify why the test comments were removed? I noticed some tests were updated because the code changed, and in those cases the comments should be updated accordingly. However, for the test I’m looking at, there were no functional changes—yet the related comment was still deleted. I also saw several similar comment deletions elsewhere in the PR. Could you please double-check whether these were intentional, or whether an automated cleanup mistakenly removed those comments?

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.

[Feature] Support a bounded row-group sliding window for Parquet prefetch

3 participants