zeroshade opened a new issue, #1631:
URL: https://github.com/apache/arrow-go/issues/1631
### Describe the bug, including details regarding any error messages,
version, and platform.
The zstd codec in `parquet/compress` has the same `testing/synctest` problem
as #1629 in `arrow/ipc`, but with a different cause.
`parquet/compress/zstd.go` keeps process-wide zstd state:
- one decoder and one encoder, each created once through `sync.Once` and
used with `DecodeAll`/`EncodeAll`
- `sync.Pool`s of encoders for `EncodeLevel` (used with `EncodeAll`) and of
decoders for `NewReader`
Both `DecodeAll` and `EncodeAll` receive from a channel inside the decoder
or encoder. A channel made inside a `testing/synctest` bubble must not be used
outside it. If a process makes its first parquet zstd call inside a bubble, the
shared decoder's channel belongs to that bubble, and every later call outside
it aborts:
```
fatal error: receive on synctest channel from outside bubble
```
With a decoder and an encoder round trip in a fresh process, using the codec
in a bubble first and then outside it failed 10 out of 10 runs. The reverse
order (outside first, then in a bubble) passed every time.
```go
codec, _ := compress.GetCodec(compress.Codecs.Zstd)
roundTrip := func() { codec.Decode(make([]byte, len(src)), codec.Encode(nil,
src)) }
synctest.Test(t, func(t *testing.T) { roundTrip() })
roundTrip() // fatal error
```
### Why this isn't fixed alongside #1629
The `arrow/ipc` fix (#1630) gives each reader its own decoders, which is
cheap because a reader lives for a whole stream or file. In `parquet/compress`,
`GetCodec` is called once per column chunk and the `Codec` interface has no
owner object, so every bubble-safe design costs production performance:
- Decoders have to be kept out of process-wide state. Each new decoder
allocates about 150 KiB of buffers on its first page.
- `EncodeAll` can't be used on shared encoders. The streaming API with a
concurrency of one uses no channels, but it copies the input and output.
I prototyped decoders scoped to each `GetCodec` call plus streaming
encoders, then ran end-to-end pqarrow benchmarks (zstd, int64 columns, 4 row
groups, Apple M4, 8 runs):
| Case | Time | Memory |
|---|---|---|
| Read, 16 columns | +9.5% | +11.6% |
| Read, 64 columns | +9.9% | +58.9% |
| Write, 16 columns | +3.3% | no change |
| Write, 64 columns | +2.2% | -1.9% |
A cheaper option is to scope codecs to `file.Reader` and `file.Writer` and
pass them down to the page readers and writers. That would cost about one
decoder per open file and one encoder per file writer, with no change on the
hot path, at the price of more plumbing.
Whether a bug that only affects tests is worth any production cost is a
maintainer decision, so this issue records the options.
### Component(s)
Parquet
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]