Skip to content

cpp, go: default LZ4 to fast mode, matching the other writers - #1807

Merged
clalancette merged 1 commit into
mainfrom
clalancette/lz4-default-fast
Aug 12, 2026
Merged

cpp, go: default LZ4 to fast mode, matching the other writers#1807
clalancette merged 1 commit into
mainfrom
clalancette/lz4-default-fast

Conversation

@clalancette

Copy link
Copy Markdown
Contributor

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.

### 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>

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@clalancette
clalancette merged commit b6b85df into main Aug 12, 2026
31 checks passed
@clalancette
clalancette deleted the clalancette/lz4-default-fast branch August 12, 2026 21:04
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