8000 rust: configurable compression level and threads by chriso · Pull Request #1394 · foxglove/mcap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

rust: configurable compression level and threads #1394

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

Conversation

chriso
Copy link
Contributor
@chriso chriso commented Jun 12, 2025

Changelog

This PR adds two new write options:

  • compression_level: u32 – compression level to use for zstd/lz4, or zero to use the default compression level.
  • compression_threads: u32 - number of threads to use for compression, or zero to disable multithreaded compression.

Docs

None? Let me know if I need to update docs somewhere.

Description

Prior to this PR, it wasn't possible to set the compression level; the default lz4 and zstd compression levels were used. Now, it's possible to set the lz4 and zstd compression levels.

Prior to this PR, non-wasm targets were forced to use multithreaded zstd compression (reference). Now, it's possible to disable multithreaded compression, or to use a different number of compression threads.

lz4 supports multithreaded compression as of v1.10.0 (see [1] and [2]), but this feature doesn't seem to be accessible from the lz4 / lz4-sys crates. For now, the compression_level option is ignored when using lz4 compression. Let me know if we should print a warning or fail.

I made these write options rather than parameterizing the Compression enum variants, because these particular options are orthogonal to the compression algorithm, and because they're only applicable to writers.

// Enable multithreaded encoding on non-WASM targets.
#[cfg(not(target_arch = "wasm32"))]
enc.set_parameter(zraw::CParameter::NbWorkers(num_cpus::get_physical() as u32))?;
enc.set_parameter(zraw::CParameter::NbWorkers(compression_threads))?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A value of 1 means one background thread. Zero disables extra threads entirely. See https://github.com/gyscos/zstd-rs/blob/229054099aa73f7e861762f687d7e07cac1d9b3b/zstd-safe/src/lib.rs#L2228

lz4::EncoderBuilder::new()
.level(compression_level)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor
@bennetthardwick bennetthardwick left a comment

Choose a reason for hiding this comment

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

Thanks @chriso!

@bennetthardwick bennetthardwick merged commit 08ac491 into foxglove:main Jun 12, 2025
23 checks passed
@chriso
Copy link
Contributor Author
chriso commented Jun 12, 2025

Thanks for the quick review @bennetthardwick! Out of interest, how often is the crate updated? I'm happy to submit a PR to bump the Cargo.toml version if that helps.

@bennetthardwick
Copy link
Contributor

That'd be great - I should have asked you to chuck it in this one. We don't have any specific release cycles, we'll just put out a new release as things accumulate.

@chriso chriso mentioned this pull request Jun 12, 2025
@chriso
Copy link
Contributor Author
chriso commented Jun 12, 2025

Thanks @bennetthardwick. See #1395

bennetthardwick pushed a commit that referenced this pull request Jun 12, 2025
### Changelog

This PR bumps the Rust crate version from `0.18.0` to `0.19.0`

### Docs

None

### Description

Changes since 0.18.0:
* #1394
* #1391

For context, see
#1394 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0