-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(conductor, relayer)!: brotli compress data blobs (#1006)
## Summary Uses brotli level 5 to compress data posted to celestia in relayer, and decompresses from read in conductor. ## Background Data size is largest component of DA costs, compression can reduce costs of data posting. Based on research, and testing brotli level 5 provides us fast enough compression with a good compression ratio for encoded protobuf data. ## Changes - compression with brotli in relayer - decompression in conductor ## Testing updated blackbox tests, smoke test on the repo ## Metrics - `TOTAL_ASTRIA_BLOB_DATA_SIZE_FOR_BLOCK` - the total sum of bytes which are in the data field of blobs for a single sequencer block - `COMPRESSION_RATIO_FOR_ASTRIA_BLOCK` - the compression ratio of data for the sequencer block
- Loading branch information
Showing
10 changed files
with
194 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::io::Write as _; | ||
|
||
use brotli::{ | ||
enc::BrotliEncoderParams, | ||
CompressorWriter, | ||
DecompressorWriter, | ||
}; | ||
|
||
const BROTLI_BUFFER_SIZE: usize = 4096; | ||
|
||
/// Decompresses the given bytes using the Brotli algorithm. | ||
/// | ||
/// Returns the decompressed bytes. | ||
/// | ||
/// # Errors | ||
/// | ||
/// Returns an error if the decompression fails. | ||
pub fn decompress_bytes(data: &[u8]) -> Result<Vec<u8>, std::io::Error> { | ||
// Header blobs are small and occur frequently with low compression, capacity based on expecting | ||
// those to be the most common case and reduce allocations. | ||
let mut output = Vec::with_capacity(data.len()); | ||
{ | ||
let mut decompressor = DecompressorWriter::new(&mut output, BROTLI_BUFFER_SIZE); | ||
decompressor.write_all(data)?; | ||
} | ||
|
||
Ok(output) | ||
} | ||
|
||
/// Compresses the given bytes using the Brotli algorithm at setting 5. | ||
/// | ||
/// Returns the compressed bytes. | ||
/// | ||
/// # Errors | ||
/// | ||
/// Returns an error if the compression fails. | ||
pub fn compress_bytes(data: &[u8]) -> Result<Vec<u8>, std::io::Error> { | ||
let compression_params = BrotliEncoderParams { | ||
quality: 5, | ||
size_hint: data.len(), | ||
..Default::default() | ||
}; | ||
// Header blobs are small and occur frequently with low compression, capacity based on expecting | ||
// those to be the most common case and reduce allocations. | ||
let mut output = Vec::with_capacity(data.len()); | ||
{ | ||
let mut compressor = | ||
CompressorWriter::with_params(&mut output, BROTLI_BUFFER_SIZE, &compression_params); | ||
compressor.write_all(data)?; | ||
} | ||
|
||
Ok(output) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters