diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c7c2137..a394e45 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,9 @@ name: Go -on: [push, pull_request] +on: + push: + branches: + - master + pull_request: jobs: build: name: Build on limited environment @@ -14,7 +18,7 @@ jobs: strategy: matrix: os: [ "ubuntu-latest", "macos-latest", "windows-latest" ] - go-version: [ "1.14", "1.15", "1.16" ] + go-version: [ "1.15", "1.16", "1.17" ] runs-on: ${{ matrix.os }} steps: - name: setup Go ${{ matrix.go-version }} @@ -38,13 +42,13 @@ jobs: - name: setup Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.17 - name: checkout ( feature ) uses: actions/checkout@v2 - name: run benchmark ( feature ) run: cd benchmarks && go test -bench GoJson | tee $HOME/new.txt - - name: install benchcmp - run: go get -u golang.org/x/tools/cmd/benchcmp + - name: install benchstat + run: go install golang.org/x/perf/cmd/benchstat@latest - name: checkout ( master ) uses: actions/checkout@v2 with: @@ -52,7 +56,7 @@ jobs: - name: run benchmark ( master ) run: cd benchmarks && go test -bench GoJson | tee $HOME/old.txt - name: compare benchmark results - run: benchcmp $HOME/old.txt $HOME/new.txt + run: benchstat $HOME/old.txt $HOME/new.txt coverage: name: Coverage runs-on: ubuntu-latest @@ -60,7 +64,7 @@ jobs: - name: setup Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.17 - name: checkout uses: actions/checkout@v2 - name: measure coverage diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 90644c7..eb441f7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,5 +1,9 @@ name: lint -on: [pull_request, push] +on: + push: + branches: + - master + pull_request: jobs: golangci: name: lint diff --git a/benchmarks/decode_test.go b/benchmarks/decode_test.go index f963263..0626219 100644 --- a/benchmarks/decode_test.go +++ b/benchmarks/decode_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "testing" - "github.com/bytedance/sonic" gojay "github.com/francoispqt/gojay" gojson "github.com/goccy/go-json" jsoniter "github.com/json-iterator/go" @@ -44,16 +43,6 @@ func Benchmark_Decode_SmallStruct_Unmarshal_SegmentioJson(b *testing.B) { } } -func Benchmark_Decode_SmallStruct_Unmarshal_Sonic(b *testing.B) { - b.ReportAllocs() - for n := 0; n < b.N; n++ { - result := SmallPayload{} - if err := sonic.Unmarshal(SmallFixture, &result); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) { b.ReportAllocs() for n := 0; n < b.N; n++ { @@ -185,16 +174,6 @@ func Benchmark_Decode_MediumStruct_Unmarshal_FastJson(b *testing.B) { } } -func Benchmark_Decode_MediumStruct_Unmarshal_Sonic(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - result := MediumPayload{} - if err := sonic.Unmarshal(MediumFixture, &result); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Decode_MediumStruct_Unmarshal_SegmentioJson(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -336,16 +315,6 @@ func Benchmark_Decode_LargeStruct_Unmarshal_FastJson(b *testing.B) { } } -func Benchmark_Decode_LargeStruct_Unmarshal_Sonic(b *testing.B) { - b.ReportAllocs() - for n := 0; n < b.N; n++ { - result := LargePayload{} - if err := sonic.Unmarshal(LargeFixture, &result); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Decode_LargeStruct_Unmarshal_SegmentioJson(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { diff --git a/benchmarks/encode_test.go b/benchmarks/encode_test.go index 59575ce..4da8034 100644 --- a/benchmarks/encode_test.go +++ b/benchmarks/encode_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "testing" - "github.com/bytedance/sonic" gojay "github.com/francoispqt/gojay" gojson "github.com/goccy/go-json" jsoniter "github.com/json-iterator/go" @@ -78,15 +77,6 @@ func Benchmark_Encode_SmallStruct_SegmentioJson(b *testing.B) { } } -func Benchmark_Encode_SmallStruct_Sonic(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - if _, err := sonic.Marshal(NewSmallPayload()); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Encode_SmallStruct_GoJsonColored(b *testing.B) { colorOpt := gojson.Colorize(gojson.DefaultColorScheme) b.ReportAllocs() @@ -186,16 +176,6 @@ func Benchmark_Encode_SmallStructCached_SegmentioJson(b *testing.B) { } } -func Benchmark_Encode_SmallStructCached_Sonic(b *testing.B) { - cached := NewSmallPayload() - b.ReportAllocs() - for i := 0; i < b.N; i++ { - if _, err := sonic.Marshal(cached); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Encode_SmallStructCached_GoJsonColored(b *testing.B) { cached := NewSmallPayload() colorOpt := gojson.Colorize(gojson.DefaultColorScheme) @@ -282,15 +262,6 @@ func Benchmark_Encode_MediumStruct_SegmentioJson(b *testing.B) { } } -func Benchmark_Encode_MediumStruct_Sonic(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - if _, err := sonic.Marshal(NewMediumPayload()); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Encode_MediumStruct_GoJsonColored(b *testing.B) { colorOpt := gojson.Colorize(gojson.DefaultColorScheme) b.ReportAllocs() @@ -380,16 +351,6 @@ func Benchmark_Encode_MediumStructCached_SegmentioJson(b *testing.B) { } } -func Benchmark_Encode_MediumStructCached_Sonic(b *testing.B) { - cached := NewMediumPayload() - b.ReportAllocs() - for i := 0; i < b.N; i++ { - if _, err := sonic.Marshal(cached); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Encode_MediumStructCached_GoJsonColored(b *testing.B) { cached := NewMediumPayload() colorOpt := gojson.Colorize(gojson.DefaultColorScheme) @@ -476,15 +437,6 @@ func Benchmark_Encode_LargeStruct_SegmentioJson(b *testing.B) { } } -func Benchmark_Encode_LargeStruct_Sonic(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - if _, err := sonic.Marshal(NewLargePayload()); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Encode_LargeStruct_GoJsonColored(b *testing.B) { colorOpt := gojson.Colorize(gojson.DefaultColorScheme) b.ReportAllocs() @@ -574,16 +526,6 @@ func Benchmark_Encode_LargeStructCached_SegmentioJson(b *testing.B) { } } -func Benchmark_Encode_LargeStructCached_Sonic(b *testing.B) { - cached := NewLargePayload() - b.ReportAllocs() - for i := 0; i < b.N; i++ { - if _, err := sonic.Marshal(cached); err != nil { - b.Fatal(err) - } - } -} - func Benchmark_Encode_LargeStructCached_GoJsonColored(b *testing.B) { cached := NewLargePayload() colorOpt := gojson.Colorize(gojson.DefaultColorScheme) diff --git a/benchmarks/go.mod b/benchmarks/go.mod index ba77afb..73ca9db 100644 --- a/benchmarks/go.mod +++ b/benchmarks/go.mod @@ -3,13 +3,13 @@ module benchmark go 1.12 require ( - github.com/bytedance/sonic v0.0.0-20210621033418-85a0d4219f94 github.com/francoispqt/gojay v1.2.13 github.com/goccy/go-json v0.0.0-00010101000000-000000000000 github.com/json-iterator/go v1.1.10 github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 github.com/segmentio/encoding v0.2.4 + github.com/stretchr/testify v1.7.0 // indirect github.com/valyala/fastjson v1.6.3 github.com/wI2L/jettison v0.7.1 ) diff --git a/benchmarks/go.sum b/benchmarks/go.sum index 9770754..fd8aa9b 100644 --- a/benchmarks/go.sum +++ b/benchmarks/go.sum @@ -12,10 +12,6 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= -github.com/bytedance/sonic v0.0.0-20210621033418-85a0d4219f94 h1:+PwepVHd43KuN9mFnAgB4962W/zuF/RGsM7B73Dyt+8= -github.com/bytedance/sonic v0.0.0-20210621033418-85a0d4219f94/go.mod h1:+QewJQ2P8nkGhdzk5fHTSwRn03eDeJAbHWIlQnv95J4= -github.com/chenzhuoyu/base64x v0.0.0-20210528162528-3c6c11c43ee5 h1:7AStn2tanqGY99xzW+Ve1p6YYqnRr1m/yswJ4h0BhcY= -github.com/chenzhuoyu/base64x v0.0.0-20210528162528-3c6c11c43ee5/go.mod h1:NfDzX8KeqVNX62apij1OkqoeDdq1VR3g0TRZo99kkBA= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -51,14 +47,11 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:Fecb github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/cpuid/v2 v2.0.6 h1:dQ5ueTiftKxp0gyjKSx5+8BtPWkyQbd95m8Gys/RarI= -github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -121,17 +114,11 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= -github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= -github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= -github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc= github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU= @@ -200,8 +187,8 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/docker-compose.yml b/docker-compose.yml index e510666..48415e3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: go-json: - image: golang:1.16 + image: golang:1.17 volumes: - '.:/go/src/go-json' deploy: