Commit 45b64e3
cpp: align zstd default level and chunk flush behavior with other writers (#1804)
### Changelog
The C++ zstd compression defaults were aligned with the rest of the
languages by switching to compression level 3, which is slightly slower
but provides better compression.
### Docs
None.
### Description
The C++ writer diverged from the Go, Rust, Python, and TypeScript MCAP
writers in two ways that produce noticeably larger zstd files:
1. CompressionLevel::Default mapped to zstd level 1, while every other
implementation compresses at libzstd's default of level 3 (Go's
SpeedDefault is the equivalent). Change the mapping to 3.
2. chunkSize was treated as a hard cap: the writer flushed the current
chunk before writing any message that would push it past the target. All
other implementations treat chunkSize as a threshold, flushing only
after the chunk meets or exceeds it. Remove the pre-write flush so chunk
boundaries match, and update the chunkSize documentation to describe the
threshold semantics.
On a simulated 10-second robot recording (5 channels, 3750 messages,
~102 MB uncompressed), these two changes together shrink the C++ zstd
output from 42.7 MB to 29.3 MB, with chunk boundaries now byte-identical
to those produced by the Rust/Go/Python writers. Writes get
correspondingly slower (level 3 costs ~35% more CPU than level 1) but
remain the fastest of the five implementations on the same workload.
The "Message index records" unit test assumed the cap behavior (its
second message relied on the pre-write flush to start a new chunk); size
each message to cross the threshold on its own instead, which preserves
the regression the test guards against.
One important compatibility note: while this does change the defaults,
it will not affect rosbag2 out-of-the-box since it explicitly chooses
uncompressed as its default.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 6fa700b commit 45b64e3
3 files changed
Lines changed: 11 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
580 | | - | |
581 | 580 | | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | 581 | | |
589 | 582 | | |
590 | 583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
555 | | - | |
| 555 | + | |
556 | 556 | | |
557 | 557 | | |
558 | 558 | | |
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
581 | 580 | | |
582 | 581 | | |
583 | 582 | | |
| |||
0 commit comments