Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use faster gzip package #982

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions compress/compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package compress_test

import (
"bytes"
stdgzip "compress/gzip"
"context"
"fmt"
"io"
Expand All @@ -16,6 +15,7 @@ import (
"text/tabwriter"
"time"

gz "github.com/klauspost/compress/gzip"
"github.com/segmentio/kafka-go"
pkg "github.com/segmentio/kafka-go/compress"
"github.com/segmentio/kafka-go/compress/gzip"
Expand Down Expand Up @@ -345,7 +345,7 @@ func BenchmarkCompression(b *testing.B) {
}
defer f.Close()

z, err := stdgzip.NewReader(f)
z, err := gz.NewReader(f)
if err != nil {
b.Fatal(err)
}
Expand All @@ -366,8 +366,6 @@ func BenchmarkCompression(b *testing.B) {
fmt.Println(ts)
}()

b.ResetTimer()

for i := range benchmarks {
benchmark := &benchmarks[i]
ratio := 0.0
Expand All @@ -389,6 +387,7 @@ func benchmarkCompression(b *testing.B, codec pkg.Codec, buf *bytes.Buffer, payl
b.Run("compress", func(b *testing.B) {
compressed = true
r := bytes.NewReader(payload)
b.ReportAllocs()

for i := 0; i < b.N; i++ {
buf.Reset()
Expand Down Expand Up @@ -422,7 +421,7 @@ func benchmarkCompression(b *testing.B, codec pkg.Codec, buf *bytes.Buffer, payl

b.Run("decompress", func(b *testing.B) {
c := bytes.NewReader(buf.Bytes())

b.ReportAllocs()
for i := 0; i < b.N; i++ {
c.Reset(buf.Bytes())
r := codec.NewReader(c)
Expand Down
3 changes: 2 additions & 1 deletion compress/gzip/gzip.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gzip

import (
"compress/gzip"
"io"
"sync"

"github.com/klauspost/compress/gzip"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/segmentio/kafka-go
go 1.15

require (
github.com/klauspost/compress v1.15.7
github.com/klauspost/compress v1.15.9
github.com/pierrec/lz4/v4 v4.1.15
github.com/stretchr/testify v1.8.0
github.com/xdg/scram v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/klauspost/compress v1.15.7 h1:7cgTQxJCU/vy+oP/E3B9RGbQTgbiVzIJWIKOLoAsPok=
github.com/klauspost/compress v1.15.7/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0=
github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
3 changes: 1 addition & 2 deletions gzip/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
package gzip

import (
gz "compress/gzip"

gz "github.com/klauspost/compress/gzip"
"github.com/segmentio/kafka-go/compress/gzip"
)

Expand Down