← Back to Pull requests

plugin/zlib: Add zlib implementation using SIMD Adler-32 #29

Closed
unknown closed this pull request without merging on Dec 02, 2026 23:29 UTC
View on GitHub
unknown unknown commented on Dec 02, 2026 14:56 UTC
Author

Stacked on #28.

Neither compress/zlib nor klauspost/compress/zlib lets callers replace the Adler-32 checksum, as both call hash/adler32 directly. To use the SIMD implementation from github.com/go-git/x/simd/adler32, the zlib framing has to be owned here.

This adds plugin/zlib (github.com/go-git/x/plugin/zlib), a zlib (RFC 1950) reader and writer with the same API as compress/zlib. It uses klauspost/compress/flate for deflate and simd/adler32 for checksums. It returns the compress/zlib error values, as klauspost/compress/zlib does, so errors.Is checks keep working. It works as a drop-in replacement through an import change, and Provider registers it with go-git's zlib plugin:

plugin.Register(plugin.Zlib(), func() plugin.ZlibProvider { return zlib.Provider{} })

Benchmarks

Against klauspost/compress/zlib:

| Workload | Change |
| --- | --- |
| Compress and decompress, all platforms tested | 2–17% faster |
| go-git packfile scanning, parsing and encoding (amd64) | 2–7% faster |
| go-git loose objects of 64 KiB and larger (amd64) | 19–29% faster |

The go-git numbers come from the go-git and spinnaker fixture packs. The benchmarks are in internal/gogitbench and take -zlib=stdlib|klauspost|simd.

Testing

  • Streams written by this package and by compress/zlib are checked to decode with the other, and headers to match byte for byte at every level.

  • Covered behaviour: preset dictionaries, malformed headers and checksums, Reset after Close, and Flush.

  • When the source implements io.ByteReader, the reader is checked not to read past the end of the stream, as go-git's packfile scanner relies on that.

  • Constructors return a nil interface on error, not one holding a nil pointer.

  • Provider passes go-git's ValidateProvider.

  • Fuzz targets round-trip data and feed malformed streams to the reader, comparing the output and the zlib errors with compress/zlib.
  • Behaviour differences from klauspost/compress/zlib

  • It requires klauspost/compress v1.20.5. Earlier versions accept a dynamic block with no end-of-block code, which RFC 1951 forbids and compress/zlib and C zlib reject. With a matching trailer, klauspost/compress/zlib v1.20.4 returns such a stream as valid data. A regression test covers it.

  • A Writer used after Close returns errors. In klauspost/compress/zlib, a second Close or a Flush panics, and a Write reports success without writing. A second Close here returns the result of the first and writes nothing more, unlike compress/zlib, which writes the trailer again.

  • Errors from the destination while writing the header are returned as is, as compress/zlib does.
  • Dependency on simd

    go.mod requires github.com/go-git/x/simd at v0.0.0-20261202164648-e9e62b7cc5c8, the pseudo-version of #28's head commit, with no replace directive. Once simd is tagged, this moves to the tag.

    Licensing

    The reader and writer are derived from Go's compress/zlib and carry Go's BSD licence notice.

    Generated with Claude Code

    Diff: 382 lines (+286 / -96) across 4 files Reviewer: pjbgf Review duration: 513m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 382 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.356
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #29"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.0% (MEDIUM) · Higher = larger blast radius
    43.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.0% · Safe to merge
    17.0%
    Repository