Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++][Parquet] Reuse memory of passed array in ConvertToDecimal #38881

Open
Hattonuri opened this issue Nov 25, 2023 · 0 comments · May be fixed by #39054
Open

[C++][Parquet] Reuse memory of passed array in ConvertToDecimal #38881

Hattonuri opened this issue Nov 25, 2023 · 0 comments · May be fixed by #39054

Comments

@Hattonuri
Copy link
Contributor

Hattonuri commented Nov 25, 2023

Describe the enhancement requested

I am reading an arrow::ListArray of Decimal128 from FixedLengthBinaryArray[16] in parquets and see on flamegraph that RawBytesToDecimalBytes consumes large amount of time and mostly due to page faults.
image
image

I assume that the problem happens here

// allocate memory for the decimal array
ARROW_ASSIGN_OR_RAISE(auto data, ::arrow::AllocateBuffer(length * type_length, pool));
// raw bytes that we can write to
uint8_t* out_ptr = data->mutable_data();
// convert each FixedSizeBinary value to valid decimal bytes
const int64_t null_count = fixed_size_binary_array.null_count();
using DecimalType = typename DecimalTypeTrait<DecimalArrayType>::value;
if (null_count > 0) {
for (int64_t i = 0; i < length; ++i, out_ptr += type_length) {
if (!fixed_size_binary_array.IsNull(i)) {
RETURN_NOT_OK(RawBytesToDecimalBytes<DecimalType>(
fixed_size_binary_array.GetValue(i), byte_width, out_ptr));
} else {
std::memset(out_ptr, 0, type_length);
}

when arrow allocates new buffer for decimals and then parses FLBA into it.
As FLBA type has the same amount of memory per element i guess that this function should reuse given array data.

Possible easy(but very dirty) solution could be static_cast given array to Decimal array (as it does not have additional fields - it wouldn't be an error), const_cast raw_values of it and reverse byte order in-place
Another benefit is reducing memory usage of reading them

Component(s)

C++, Parquet

@Hattonuri Hattonuri changed the title Reuse memory of passed array in ConvertToDecimal [C++][Parquet] Reuse memory of passed array in ConvertToDecimal Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant