perf(dotc1z): pool zstd encoders and decoders to reduce allocations #773
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 410 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.360
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #773"
general
weight: 0.35
arreyder
Reviving #622 (closed, not merged). This re-opens the same branch with btipling's two non-blocking follow-ups from the prior review folded in.
Summary
sync.Poolforzstd.Encoderandzstd.Decoderto eliminate per-call allocation overhead on the dotc1z hot path.zstd.ensureHistallocating ~215 MB/min intemporal_syncfrom encoder churn, and the decoder side allocating ~3.2 GB/min intemporal_worker.Changes
| File | Change |
|---|---|
|
pkg/dotc1z/pool.go| NEW — encoder/decoder pool withget/puthelpers ||
pkg/dotc1z/pool_test.go| NEW — unit tests, concurrent stress, round-trip, benchmarks ||
pkg/dotc1z/file.go|saveC1zuses pooled encoder when concurrency matches ||
pkg/dotc1z/decoder.go| decoder uses pooled decoder when options match |Follow-ups from prior review (new in this revival)
1. Pool now engages at the production default. In the prior PR,
pooledEncoderConcurrency = GOMAXPROCSbut the callers default toencoderConcurrency = 1, so the gate atfile.go:158was always false and the pool carried zero traffic in prod. PinningpooledEncoderConcurrency = 1makes the pool match the actual sync-path default. The alternative — flipping callers to0(→GOMAXPROCS) — was deliberately avoided because klauspost/compress's multi-threaded encoder has theoretical race concerns.2. Pool-growth tests are now hermetic.
TestPoolGrowsFromSaveC1z,TestPoolGrowsFromDecoder,TestEncoderPool, andTestDecoderPoolnow swap the package-globalsync.Poolviat.Cleanup, so GC eviction and cross-test ordering can't flake the exact-membership assertions. The package globals became pointer-valued to allow the swap.Safety Measures
Reset(nil)called before returning to pool to release writer/reader references.Reset()errors handled gracefully (don't return bad decoders to pool).Benchmark (apples-to-apples at concurrency=1)
~15,000x reduction in bytes allocated per encode.
Production Profile Context
temporal_sync(60s profile):zstd.(*fastBase).ensureHist≈ 384 MB, total zstd allocs ≈ 665 MB (12.4% of total).temporal_worker(62s profile): decoder-side allocs ≈ 3.26 GB (17.9% of total) viaprotozstd.Unmarshal→decompressValue.Test plan
dotc1ztests passPrior approval: @btipling on #622.
🤖 Generated with Claude Code