sunchao commented on code in PR #7606: URL: https://github.com/apache/datafusion-comet/pull/7606#discussion_r4735341632
########## native/shuffle/src/lz4_frame.rs: ########## @@ -0,0 +1,325 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! LZ4 frames written with buffers and a hash table kept from one frame to the next. +//! +//! Every compressed shuffle block is one LZ4 frame. [`Lz4FrameEncoder`] writes the frame format +//! itself around lz4_flex's block compressor, compressing whole blocks straight from the +//! caller's buffer and writing each block out as soon as it is compressed. One +//! `lz4_flex::frame::FrameEncoder<Vec<u8>>` kept from frame to frame would reuse its state too, +//! but it measured no faster than a new encoder per frame on 8192-row blocks +//! (`benches/shuffle_writer.rs`), and it holds each whole compressed frame until it is copied out. +//! +//! The frames have independent blocks of at most 64 KiB, no block or content checksums, no +//! content size and an end mark. A block that does not get smaller is stored uncompressed, as +//! `FrameEncoder` does. + +use lz4_flex::block::{compress_into_with_table, get_maximum_output_size, CompressTable}; +use std::io::{self, Write}; + +/// Uncompressed bytes per block: the frame format's smallest block maximum, which every LZ4 +/// reader decodes with the least memory. +const BLOCK_SIZE: usize = 64 * 1024; Review Comment: Could we keep adaptive sizing for local writes when the cached schema message exceeds 64 KiB? Falling back to the previous `FrameEncoder` for that case would keep the fast path for ordinary schemas and the existing 64 KiB bound for remote shuffle. I compared `ShuffleBlockWriter::write_batch` on the base and this PR with 8,192 rows and 1,600 `Int32` columns, `c_i[row] = row + i`. Each column has 32 KiB of values. The smaller independent blocks cut off matches between neighboring columns more often. The compressed frame grew from 13,369,635 bytes (256 KiB blocks) to 26,508,688 bytes (64 KiB blocks). Forcing the old encoder to 64 KiB produced 26,508,600 bytes. With 512 columns both versions used 64 KiB and differed by just 46 bytes. Could we include compressed bytes in the wide-schema benchmark alongside encode time? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
