Skip to content

GH-55855: [C++][Parquet] Avoid copying the values buffer for V2 data pages without levels - #55856

Merged
HuaHuaY merged 2 commits into
apache:mainfrom
HuaHuaY:avoid_copy_page
Dec 1, 2026
Merged

HuaHuaY merged 2 commits into
apache:mainfrom
HuaHuaY:avoid_copy_page

Conversation

@HuaHuaY

@HuaHuaY HuaHuaY commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

When a V2 data page has no repetition or definition levels, its values buffer is already the complete payload. Copying it into a separate page buffer adds one allocation and one copy per page.

What changes are included in this PR?

Refactor BuildDataPageV2.

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI balanced review requested due to automatic review settings November 30, 2026 11:25
ConcatenateBuffers(definition_levels_rle_size, repetition_levels_rle_size,
compressed_values, combined->mutable_data());
std::shared_ptr<Buffer> page_buffer =
page_is_compressed ? compressor_temp_buffer_ : values;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is an issue here, though I am not sure if it should block this PR.

PageWriter is a pure virtual class with the method signature virtual int64_t WriteDataPage(const DataPage& page) = 0. If a custom class inherits from PageWriter and invokes std::shared_ptr<Buffer> Page::buffer() const { return buffer_; }, it can retrieve a shared_ptr from the const DataPage& page argument.

However, with this change, compressor_temp_buffer_ is written out directly; consequently, downstream components can no longer rely on this shared_ptr remaining valid during the next call to BuildDataPageV2. That said, the fact that const DataPage& page is passed as an argument arguably carries the implicit semantic that the page object might become invalid after the call returns.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I discovered that BuildDataPageV1 already contained similar code six years ago.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Refactors Parquet V2 data page construction to avoid unnecessary payload copies when pages have no def/rep levels, reducing per-page allocation/copy overhead.

Changes:

  • Update ColumnWriterImpl::BuildDataPageV2 to reuse the existing values buffer as the page payload when possible.
  • Buffer/copy page payload only when levels are present or when pages must be retained for dictionary encoding.
  • Refactor and expand multi-page roundtrip tests to cover additional configurations (including V2 + ZSTD paths under ARROW_WITH_ZSTD).
File Description
cpp/​src/​parquet/​file_serialize_test.cc Refactors multi-page roundtrip test into a helper and adds additional scenarios (incl. V2/ZSTD and dictionary toggles).
cpp/​src/​parquet/​column_writer.cc Avoids concatenation/copy when levels aren’t present; only allocates when levels exist or the page must be buffered for dictionary encoding.

Review effort: Lite

Comment on lines +1105 to 1108
DataPageV2 page(page_buffer, num_values, null_count, num_rows, encoding_,
def_levels_byte_length, rep_levels_byte_length, uncompressed_size,
page_is_compressed, std::move(page_stats), first_row_index,
std::move(page_size_stats));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This comment was addressed earlier.

Comment thread cpp/src/parquet/column_writer.cc Resolved
Copilot AI balanced review requested due to automatic review settings November 30, 2026 11:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the Parquet writer’s values-buffer reuse optimization.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread cpp/src/parquet/file_serialize_test.cc Resolved
@HuaHuaY
HuaHuaY merged commit 00268d1 into apache:main Dec 1, 2026
55 of 56 checks passed
@HuaHuaY
HuaHuaY deleted the avoid_copy_page branch December 1, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Parquet] Avoid copying the values buffer for V2 data pages without levels

3 participants