Skip to content

Commit c445f76

Browse files
Merge pull request #415 from sonicfromnewyoke/sonic/perf-rpc-json-serde
perf(json): swap encoding/json and jsoniter for goccy/go-json
2 parents 91e8cec + 2afb213 commit c445f76

22 files changed

Lines changed: 528 additions & 42 deletions

cmd/slnc/cmd/get_account.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ package cmd
1919

2020
import (
2121
"context"
22-
"encoding/json"
2322
"fmt"
2423

2524
"github.com/gagliardetto/solana-go"
26-
25+
json "github.com/goccy/go-json"
2726
"github.com/spf13/cobra"
2827
)
2928

cmd/slnc/cmd/get_block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package cmd
1919

2020
import (
2121
"context"
22-
"encoding/json"
2322
"fmt"
2423
"strconv"
2524

25+
json "github.com/goccy/go-json"
2626
"github.com/spf13/cobra"
2727
)
2828

cmd/slnc/cmd/get_latest_blockhash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package cmd
1919

2020
import (
2121
"context"
22-
"encoding/json"
2322
"fmt"
2423

24+
json "github.com/goccy/go-json"
2525
"github.com/spf13/cobra"
2626
)
2727

cmd/slnc/cmd/get_program_accounts.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
package cmd
1919

2020
import (
21-
"encoding/json"
2221
"fmt"
2322
"os"
2423

25-
"github.com/gagliardetto/solana-go/text"
26-
2724
"github.com/gagliardetto/solana-go"
28-
25+
"github.com/gagliardetto/solana-go/text"
26+
json "github.com/goccy/go-json"
2927
"github.com/spf13/cobra"
3028
)
3129

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ require (
66
github.com/gagliardetto/binary v0.8.0
77
github.com/gagliardetto/gofuzz v1.2.2
88
github.com/gagliardetto/treeout v0.1.4
9+
github.com/goccy/go-json v0.10.6
910
github.com/google/uuid v1.6.0
11+
github.com/json-iterator/go v1.1.12
1012
github.com/mr-tron/base58 v1.2.0
1113
go.mongodb.org/mongo-driver/v2 v2.5.0
1214
)
@@ -30,7 +32,7 @@ require (
3032
github.com/mattn/go-colorable v0.1.14 // indirect
3133
github.com/mattn/go-isatty v0.0.20 // indirect
3234
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
33-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
35+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
3436
github.com/modern-go/reflect2 v1.0.2 // indirect
3537
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
3638
github.com/pmezard/go-difflib v1.0.0 // indirect
@@ -67,7 +69,6 @@ require (
6769
github.com/google/go-cmp v0.7.0
6870
github.com/gorilla/rpc v1.2.1
6971
github.com/gorilla/websocket v1.5.3
70-
github.com/json-iterator/go v1.1.12
7172
github.com/klauspost/compress v1.18.0
7273
github.com/logrusorgru/aurora v2.0.3+incompatible
7374
github.com/mostynb/zstdpool-freelist v0.0.0-20201229113212-927304c0c3b1

go.sum

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
4343
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
4444
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
4545
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
46+
github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
47+
github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
4648
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
4749
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
4850
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
@@ -94,9 +96,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
9496
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
9597
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
9698
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
99+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
97100
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
98-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
99-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
100101
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
101102
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
102103
github.com/mostynb/zstdpool-freelist v0.0.0-20201229113212-927304c0c3b1 h1:mPMvm6X6tf4w8y7j9YIt6V9jfWhL6QlbEc7CCmeQlWk=

json.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,24 @@
1515
package solana
1616

1717
import (
18-
jsoniter "github.com/json-iterator/go"
18+
"io"
19+
20+
gojson "github.com/goccy/go-json"
1921
)
2022

21-
var json = jsoniter.ConfigCompatibleWithStandardLibrary
23+
// json is a package-local alias for the JSON library in use. It keeps the
24+
// existing `json.Marshal`/`json.Unmarshal`/`json.NewDecoder`/`json.NewEncoder`
25+
// call sites working while the underlying library is swapped.
26+
var json = struct {
27+
Marshal func(v any) ([]byte, error)
28+
MarshalIndent func(v any, prefix, indent string) ([]byte, error)
29+
Unmarshal func(data []byte, v any) error
30+
NewDecoder func(r io.Reader) *gojson.Decoder
31+
NewEncoder func(w io.Writer) *gojson.Encoder
32+
}{
33+
Marshal: gojson.Marshal,
34+
MarshalIndent: gojson.MarshalIndent,
35+
Unmarshal: gojson.Unmarshal,
36+
NewDecoder: gojson.NewDecoder,
37+
NewEncoder: gojson.NewEncoder,
38+
}

programs/token-2022/json.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
package token2022
22

33
import (
4-
jsoniter "github.com/json-iterator/go"
4+
"io"
5+
6+
gojson "github.com/goccy/go-json"
57
)
68

7-
var json = jsoniter.ConfigCompatibleWithStandardLibrary
9+
var json = struct {
10+
Marshal func(v any) ([]byte, error)
11+
MarshalIndent func(v any, prefix, indent string) ([]byte, error)
12+
Unmarshal func(data []byte, v any) error
13+
NewDecoder func(r io.Reader) *gojson.Decoder
14+
NewEncoder func(w io.Writer) *gojson.Encoder
15+
}{
16+
Marshal: gojson.Marshal,
17+
MarshalIndent: gojson.MarshalIndent,
18+
Unmarshal: gojson.Unmarshal,
19+
NewDecoder: gojson.NewDecoder,
20+
NewEncoder: gojson.NewEncoder,
21+
}

programs/token/json.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@
1515
package token
1616

1717
import (
18-
jsoniter "github.com/json-iterator/go"
18+
"io"
19+
20+
gojson "github.com/goccy/go-json"
1921
)
2022

21-
var json = jsoniter.ConfigCompatibleWithStandardLibrary
23+
var json = struct {
24+
Marshal func(v any) ([]byte, error)
25+
MarshalIndent func(v any, prefix, indent string) ([]byte, error)
26+
Unmarshal func(data []byte, v any) error
27+
NewDecoder func(r io.Reader) *gojson.Decoder
28+
NewEncoder func(w io.Writer) *gojson.Encoder
29+
}{
30+
Marshal: gojson.Marshal,
31+
MarshalIndent: gojson.MarshalIndent,
32+
Unmarshal: gojson.Unmarshal,
33+
NewDecoder: gojson.NewDecoder,
34+
NewEncoder: gojson.NewEncoder,
35+
}

rpc/client_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ import (
2121
"bytes"
2222
"context"
2323
"encoding/base64"
24-
stdjson "encoding/json"
2524
"fmt"
2625
"math/big"
2726
"testing"
2827

2928
"github.com/AlekSi/pointer"
3029
bin "github.com/gagliardetto/binary"
30+
"github.com/gagliardetto/solana-go"
31+
stdjson "github.com/goccy/go-json"
3132
"github.com/stretchr/testify/assert"
3233
"github.com/stretchr/testify/require"
33-
34-
"github.com/gagliardetto/solana-go"
3534
)
3635

3736
func TestClient_GetAccountInfo(t *testing.T) {

0 commit comments

Comments
 (0)