Repository navigation
feat(arrow/ipc): add WithZstdLevel option for IPC writer - #1376
Conversation
zeroshade
left a comment
There was a problem hiding this comment.
Thanks for adding this — the level is correctly threaded through Writer, FileWriter, and GetRecordBatchPayload, and output round-trips at every level I tried. Two things before this can land: the doc comment promises more level granularity than the encoder provides, and the new option has no test coverage.
Level semantics in the doc comment (arrow/ipc/ipc.go:169)
The comment says levels 1–22 follow the Zstandard spec, but zstd.EncoderLevelFromZstd (klauspost/compress) collapses them into four encoder speeds: <3 → SpeedFastest, 3–5 → SpeedDefault, 6–9 → SpeedBetterCompression, ≥10 → SpeedBestCompression. Locally, levels 9 and 19 produced near-identical output (599,840 vs 599,872 bytes), and 0/negative levels silently use the default. Please document the mapping (and that level <= 0 means the default) so callers don't expect e.g. level 19 to differ from level 10.
Tests for WithZstdLevel
The test changes only add the new 0 argument to existing calls. Please add a test that writes with WithZstd(), WithZstdLevel(n) through both NewWriter and NewFileWriter, reads it back with RecordEqual, and shows the level takes effect (e.g. WithZstdLevel(1) vs the default yields different compressed output).
Smaller observations
arrow/ipc/ipc.go:178—WithZstdLevelwithoutWithZstdis silently ignored. Consider having it also select ZSTD, since a level only makes sense with that codec.arrow/ipc/writer.go:400—newRecordEncodernow takes nine positional args withcodec,zstdLevel, andcompressNPadjacent; easy to transpose. Consider passing the compressor configuration as one value rather than growing the signature.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. After you've
addressed the points above and pushed an update, an Apache Arrow
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.
|
Thanks for the thorough review @zeroshade! I have addressed all three points:
Regarding the 9-parameter All IPC tests pass locally ( |
|
@zeroshade Just merged main to make the PR mergeable again. All your inline comments have been resolved in my previous update — please take another look when you have a moment! |
|
Reviewed the changes: doc comment now correctly documents encoder speed bands from zstd.EncoderLevelFromZstd, level<=0 semantics, and a full test suite validates WithZstdLevel across writer types and output round-trips. Ready for re-review. |
The existing WithZstd() option enables ZSTD compression but gives callers no way to control the compression level — the encoder is always created with zstd.NewWriter(nil) which defaults to SpeedDefault (roughly zstd level 3). For producers that stream large IPC batches over the same network as the consumer, compression is a noticeable share of producer CPU, and since decompression speed barely depends on the level, a lower level (e.g. 1 / SpeedFastest) cuts producer CPU with almost no reader impact. Add WithZstdLevel(level int) Option that mirrors the existing WithZstd() API. The level is propagated through config → recordEncoder → getCompressor, which creates the encoder with zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(level)) when the option is set, or falls back to the previous default behaviour otherwise. The C++ IPC implementation already allows callers to set the ZSTD compression level via IpcWriteOptions::codec, so this brings the Go implementation in line with C++.
Signed-off-by: Apache Arrow Go Developer <[email protected]>
- Fix NewFileWriter roundtrip subtest to use FileReader API (RecordBatchAt, NumRecords, Close) instead of StreamReader API (Next, RecordBatch(), Release, Err), which FileReader does not provide. - Replace all-zeros test data with sequential integers so different zstd compression levels actually produce visibly different output sizes. All-zeros data is trivially compressible at every zstd level and produces identical output. Use level 1 (SpeedFastest) vs level 6 (SpeedBetterCompression) which span different encoder speed presets. Signed-off-by: Asthenia0412 <[email protected]>
f8b23b9 to
2132381
Compare
|
Rebased onto upstream/main to resolve merge conflicts. All reviewer threads are marked resolved. Local checks: |
|
@zeroshade — all three review points addressed: (1) WithZstdLevel godoc now documents the four-speed zstd level bands; (2) WithZstdLevel now also sets codec=ZSTD so callers don't need a separate WithZstd() call; (3) newRecordEncoder compression args bundled into a compressionSettings struct to avoid positional-transpose risk. All local checks (go build, go vet, go test ./arrow/ipc/...) pass. Ready for re-review! |
|
@zeroshade — 所有 3 个 inline review threads 均已 resolved(author push 触发自动 resolve)。Thread 1 & 2 已在 PR 原始代码中实现,Thread 3(compressionSettings 结构体重构)已在 commit b26dc4c 中落地。本地验证 go build / go vet / go test ./arrow/ipc/... 全部通过。期待你的 re-review! |
|
@zeroshade All three inline comments addressed in the latest commits:
I also expanded the TestWithZstdLevel table in the earlier push to cover NewWriter / NewFileWriter round-trips, same-preset equivalence (levels 1 and 2 both map to SpeedFastest and produce byte-identical output), and WithZstd() vs WithZstdLevel(0) equivalence. go test ./arrow/ipc/... is green. PTAL! |
|
@Asthenia0412 sorry for the delay in response here, i've been travelling for ASF community over code. I'll re-review this shortly |
zeroshade
left a comment
There was a problem hiding this comment.
Thanks for working through all of this. Every point from the earlier review is addressed: the godoc now matches EncoderLevelFromZstd, WithZstdLevel works on its own, compressionSettings removes the transposition risk, and the tests actually catch the level being ignored. I confirmed that by stubbing out the level and watching the level-1-vs-6 subtest fail. Two optional nits inline.
I'll approve once CI finishes green.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. After you've
addressed the points above and pushed an update, an Apache Arrow
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.
|
@zeroshade Thanks for the earlier review! All points have been addressed. Ready for another look. |
…0 band The <3 row overlaps the level<=0 row above it. Use the explicit range '1-2 -> SpeedFastest' so the four zstd.EncoderLevelFromZstd speed bands map cleanly without ambiguity.
zeroshade
left a comment
There was a problem hiding this comment.
Thanks. The level table now reads 1-2 -> SpeedFastest, so the rows no longer overlap. The test-helper suggestion was optional and can stay as is. LGTM.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.
Background
ipc.WithZstd()turns on ZSTD compression for IPC writers but gives callers no way to choose the level.getCompressoralways builds the encoder withzstd.NewWriter(nil), defaulting toSpeedDefault(≈ zstd level 3).For producers streaming large IPC batches over the same network as the consumer, compression is a noticeable share of producer CPU. Since decompression speed barely depends on level, level 1 (
SpeedFastest) cuts producer CPU with almost no reader impact — today the only way to get there is to patch arrow-go.What changed
WithZstdLevel(level int) Option— callers can set zstd compression level (1–22).config,Writer,FileWriter, andrecordEncoderwith a newzstdLevelfield.getCompressor(codec, zstdLevel)to usezstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(level))whenzstdLevel > 0, else falls back to the previous default.Backwards compatibility
Purely additive. Callers using
WithZstd()withoutWithZstdLevelget the exact same default behaviour as before.Testing
go build ./arrow/ipc/...✅go test -c ./arrow/ipc/...✅go test ./arrow/ipc/... -count=1✅ (all existing tests pass)Alignment with C++
The C++ IPC implementation already lets callers set the ZSTD compression level via
IpcWriteOptions::codecbuilt fromutil::Codec::Create(Compression::ZSTD, level). This change brings Go in line with C++.Resolves #1368
Signed-off-by: yancy [email protected]