Skip to content

GH-55448: [C++][Parquet] Optimize ALP and support per-column vector sizes - #55449

Open
wgtmac wants to merge 8 commits into
apache:mainfrom
wgtmac:alp_improve
Open

wgtmac wants to merge 8 commits into
apache:mainfrom
wgtmac:alp_improve

Conversation

@wgtmac

@wgtmac wgtmac commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

This PR addresses follow-up items from #48345 to improve ALP performance, format compatibility, and writer configuration.

What changes are included in this PR?

  • Add EncodingOptions and AlpOptions to configure the ALP vector size globally or per column.
  • Accept unsorted and duplicate exception positions. Use a vectorizable bounds and ordering check.
  • Load encoding and decoding multipliers before value loops.
  • Write each encoded vector and its offset directly to the page buffer.
  • Use stack storage for second-level sampling, avoiding a sample allocation for each vector parameter search.
  • Write non-null values directly to the encoder buffer in PutSpaced().

Are these changes tested?

Yes. I ran the ALP and Parquet tests and the new benchmarks from #55714.

Are there any user-facing changes?

Yes. Writers can set AlpOptions::vector_size through WriterProperties::Builder::encoding_options(). The default is 1,024 values. Supported sizes are powers of two from 8 through 32,768.

The exported MakeEncoder signature and writer property layouts change, so C++ consumers need to rebuild.

Was AI used for this PR?

AI assisted with implementation, review, test execution, and benchmarking.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@wgtmac
wgtmac requested review from HuaHuaY and pitrou as code owners November 9, 2026 06:05
Copilot AI balanced review requested due to automatic review settings November 9, 2026 06:05

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 06:56

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 07:39

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@pitrou pitrou left a comment

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.

Just some API notes

Comment thread cpp/src/parquet/encoding.h Resolved
Comment thread cpp/src/parquet/properties.h Resolved
Copilot AI balanced review requested due to automatic review settings November 10, 2026 07:51

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@pitrou pitrou left a comment

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 must think a bit more about the EncodingOptions API but otherwise this is looking rather good.

Comment on lines +537 to +538
// The encoder emits strictly increasing positions. Use the vectorized
// fast path for that common case.

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.

Was the "vectorized fast path" measured to bring substantial benefits? After all, there should not be many exceptions...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#48345 (comment) mentioned testing unroll factors of 2, 4 and 8, but provided no measurements specific to exception patching.

When I made this change, I have verified that the code path has been vectorized by gcc on godbolt. But I didn't verify its performance gain because I used Clang locally which failed to do this :/

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.

https://godbolt.org/z/xY51czqfq

Seem this would vectorize only with avx512f? x86 SSE4.2/AVX2 doesn't has vscatter, and unroll might only affect little performance, unroll 4 with 50% exception with only have 5% performance enhancement in my machine. And with 1-10% exception, the optimization <= 1.2% in my machine.

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 suggest we can remove this 🤔

Comment thread cpp/src/arrow/util/alp/alp_sampler.cc Resolved
Comment thread cpp/src/parquet/encoder.cc Resolved
Comment thread cpp/src/parquet/encoder.cc Resolved
Comment thread cpp/src/parquet/encoder.cc Resolved
Comment thread cpp/src/parquet/encoder.cc Resolved
Copilot AI balanced review requested due to automatic review settings November 12, 2026 05:40

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 14:58

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:00

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 12:41

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@wgtmac

wgtmac commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

@pitrou Could you help take a look again?

}
vector_offsets.push_back(static_cast<AlpFormatConstants::OffsetType>(current_offset));
current_offset += per_vector_metadata_size + vec.GetDataStoredSize();
if (stored_size > static_cast<int64_t>(body.size()) - current_offset) {

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.

Would it be useful to marking it as [[unlikely]]?

@pitrou

pitrou commented Nov 24, 2026

Copy link
Copy Markdown
Member

@wgtmac Can you rebase now that we have supplementary ALP benchmarks in git main?

Comment thread cpp/src/parquet/encoding.h Resolved
@mapleFU

mapleFU commented Nov 24, 2026

Copy link
Copy Markdown
Member

A bit weird about std::any as EncodingOptions, arrow project currently uses something like shared_ptr<BaseClass>, like CodecOptions. And std::variant<AlpEncoding, ...> can also being used? I found the status a bit weird here ( but std::any is ok for me)

Comment thread cpp/src/arrow/util/alp/alp_metadata.cc Resolved
@pitrou

pitrou commented Nov 24, 2026

Copy link
Copy Markdown
Member

Good point @mapleFU , perhaps std::variant is a better choice given that 1) the acceptable types are a predetermined small set of types (currently only one :-)), 2) we do not need to hide the actual types.

@mapleFU

mapleFU commented Nov 24, 2026

Copy link
Copy Markdown
Member

I applied this PR on top of main (with #55714) and benchmarked it on Apple M5 Max (arm64, Apple clang 21.0.0, Release build).

Hoisting the multipliers in AlpInlines<T>::GetMultipliers() unblocks Clang auto-vectorization on AArch64 for all three Decompress instantiations (float -> float, float -> double, double -> double), giving a 1.7x–3.9x decode speedup across both constant and varied inputs:

Benchmark (N = 65536) main This PR Speedup
BM_AlpDecodingFloat (constant) 7.10 GiB/s 27.96 GiB/s 3.94x
BM_AlpDecodingDouble (constant) 13.20 GiB/s 31.24 GiB/s 2.37x
BM_AlpDecodingVaried<FloatType> (exception-percent:0) 6.89 GiB/s 22.12 GiB/s 3.21x
BM_AlpDecodingVaried<FloatType> (exception-percent:1) 6.62 GiB/s 17.40 GiB/s 2.63x
BM_AlpDecodingVaried<FloatType> (exception-percent:10) 6.02 GiB/s 13.23 GiB/s 2.20x
BM_AlpDecodingVaried<DoubleType> (exception-percent:0) 13.17 GiB/s 25.68 GiB/s 1.95x
BM_AlpDecodingVaried<DoubleType> (exception-percent:1) 13.06 GiB/s 25.19 GiB/s 1.93x
BM_AlpDecodingVaried<DoubleType> (exception-percent:10) 11.58 GiB/s 19.52 GiB/s 1.69x
BM_AlpEncodingVaried<FloatType> (exception-percent:0) 956 MiB/s 967 MiB/s 1.01x
BM_AlpEncodingVaried<FloatType> (exception-percent:10) 717 MiB/s 747 MiB/s 1.04x
BM_AlpEncodingVaried<DoubleType> (exception-percent:0) 1.14 GiB/s 1.17 GiB/s 1.03x
BM_AlpEncodingVaried<DoubleType> (exception-percent:10) 1.21 GiB/s 1.19 GiB/s 0.99x

Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:32

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@wgtmac wgtmac changed the title GH-55448: [C++][Parquet] Optimize ALP and make vector sizes configurable GH-55448: [C++][Parquet] Optimize ALP and support per-column vector sizes Nov 25, 2026
@wgtmac

wgtmac commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Thanks for your review, @mapleFU and @pitrou! I've rebased and addressed all comments. Please take a look again when you have time.


WriterProperties::Builder* WriterProperties::Builder::encoding_options(
const EncodingOptions& options) {
default_column_properties_.set_encoding_options(options);

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.

why do we set default options here, bf doesn't have default options in this scenerio, I'm not sure about what's the pro of it.

}

if (!col_props.encoding_options().options.empty()) {
this->encoding_options(col_path, col_props.encoding_options());

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.

Here didn't copying from default? Or should we just not keeping the default?

Comment on lines +537 to +538
// The encoder emits strictly increasing positions. Use the vectorized
// fast path for that common case.

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 suggest we can remove this 🤔

"and FIXED_LEN_BYTE_ARRAY");
}
} else if (encoding == Encoding::ALP) {
const auto& alp_options = options.Get<AlpOptions>(encoding);

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.

Should we validate it here since it's a public API ( just DCHECK might also ok for me, I don't know)

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.

5 participants