cpp, go: default LZ4 to fast mode, matching the other writers - #1807
Merged
Conversation
### Changelog The C++ and Go writers' default LZ4 compression was changed from the high-compression codepaths (LZ4HC level 9 and pierrec Level3 respectively) to fast mode, matching the Rust and Python writers. Default LZ4 writes get roughly 3-5x faster and produce files roughly 15-30% larger. Callers that prefer ratio over speed can keep the old behavior through the existing slower CompressionLevel settings. ### Docs None. ### Description CompressionLevel::Default diverged for LZ4 across the writers: C++ mapped it to LZ4HC_CLEVEL_DEFAULT (LZ4HC level 9) and Go to pierrec lz4.Level3, while Rust and Python compress in LZ4's fast mode. (TypeScript does not ship an LZ4 writer.) High-compression LZ4 defeats the reason to pick LZ4 in the first place: both writers' own zstd defaults strictly dominate their LZ4 defaults after #1804 — on the same workload C++ zstd wrote in 710 ms producing a 71 MB file while C++ LZ4 took 2130 ms to produce 78 MB, slower and larger. Users choosing LZ4 over zstd are choosing speed. Map CompressionLevel::Default to fast mode in both writers. On 1M 100-byte messages sharing one payload blob: - C++: 2.23 s -> 0.46 s (~4.8x faster), 81 MB -> 103 MB - Go: 2.19 s -> 0.77 s (~2.9x faster), 82 MB -> 93 MB - Rust, for reference, writes the same workload in 0.67 s at its existing fast-mode default. The high-compression levels remain reachable: C++ keeps LZ4HC through CompressionLevel::Slow (LZ4HC_CLEVEL_OPT_MIN) and Slowest (LZ4HC_CLEVEL_MAX), and Go keeps lz4.Level6/Level9 through CompressionLevelBetter/Best. Go's fallback for unknown level values also follows the default to fast mode, mirroring how its zstd mapping falls back to its own default. As with #1804, rosbag2 is unaffected out of the box since it defaults to uncompressed writing. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
clalancette
requested review from
gasmith,
james-rms and
jtbandes
as code owners
August 12, 2026 20:53
james-rms
approved these changes
Aug 12, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog
The C++ and Go writers' default LZ4 compression was changed from the high-compression codepaths (LZ4HC level 9 and pierrec Level3 respectively) to fast mode, matching the Rust and Python writers. Default LZ4 writes get roughly 3-5x faster and produce files roughly 15-30% larger. Callers that prefer ratio over speed can keep the old behavior through the existing slower CompressionLevel settings.
Docs
None.
Description
CompressionLevel::Default diverged for LZ4 across the writers: C++ mapped it to LZ4HC_CLEVEL_DEFAULT (LZ4HC level 9) and Go to pierrec lz4.Level3, while Rust and Python compress in LZ4's fast mode. (TypeScript does not ship an LZ4 writer.) High-compression LZ4 defeats the reason to pick LZ4 in the first place: both writers' own zstd defaults strictly dominate their LZ4 defaults after #1804 — on the same workload C++ zstd wrote in 710 ms producing a 71 MB file while C++ LZ4 took 2130 ms to produce 78 MB, slower and larger. Users choosing LZ4 over zstd are choosing speed.
Map CompressionLevel::Default to fast mode in both writers. On 1M 100-byte messages sharing one payload blob:
The high-compression levels remain reachable: C++ keeps LZ4HC through CompressionLevel::Slow (LZ4HC_CLEVEL_OPT_MIN) and Slowest (LZ4HC_CLEVEL_MAX), and Go keeps lz4.Level6/Level9 through CompressionLevelBetter/Best. Go's fallback for unknown level values also follows the default to fast mode, mirroring how its zstd mapping falls back to its own default.
As with #1804, rosbag2 is unaffected out of the box since it defaults to uncompressed writing.