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

Consider Adding More Efficient Compression Methods to ckb-network::Message::compress/decompress #4786

Open
eval-exec opened this issue Jan 17, 2025 · 0 comments
Labels
t:enhancement Type: Feature, refactoring.

Comments

@eval-exec
Copy link
Collaborator

eval-exec commented Jan 17, 2025

Feature Request

Is your feature request related to a problem? Please describe.

In the current implementation, ckb-network only supports the Snappy compression method.

pub(crate) fn decompress(mut self) -> Result<Bytes, io::Error> {
if self.inner.is_empty() {
Err(io::ErrorKind::InvalidData.into())
} else if self.compress_flag() {
match decompress_len(&self.inner[1..]) {
Ok(decompressed_bytes_len) => {
if decompressed_bytes_len > MAX_UNCOMPRESSED_LEN {
debug!(
"The limit for uncompressed bytes len is exceeded. limit: {}, len: {}",
MAX_UNCOMPRESSED_LEN, decompressed_bytes_len
);
Err(io::ErrorKind::InvalidData.into())
} else {
let mut buf = vec![0; decompressed_bytes_len];
match SnapDecoder::new().decompress(&self.inner[1..], &mut buf) {
Ok(_) => Ok(buf.into()),
Err(e) => {
debug!("snappy decompress error: {:?}", e);
Err(io::ErrorKind::InvalidData.into())
}
}
}
}
Err(e) => {
debug!("snappy decompress_len error: {:?}", e);
Err(io::ErrorKind::InvalidData.into())
}
}
} else {
let _ = self.inner.split_to(1);
Ok(self.inner.freeze())
}
}

How about considering supporting other methods, such as lz4?

@eval-exec eval-exec added the t:enhancement Type: Feature, refactoring. label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t:enhancement Type: Feature, refactoring.
Projects
None yet
Development

No branches or pull requests

1 participant