Skip to content

Commit 3f1e8da

Browse files
authored
llo: switch to github.com/goccy/go-json to improve performance of encode/decode ops (#188)
* llo: switch to github.com/goccy/go-json to improve performance of encode/decode ops
1 parent c620bf1 commit 3f1e8da

18 files changed

+30
-21
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.24.4
77
require (
88
github.com/ethereum/go-ethereum v1.15.3
99
github.com/expr-lang/expr v1.17.5
10+
github.com/goccy/go-json v0.10.4
1011
github.com/hashicorp/go-plugin v1.6.3
1112
github.com/klauspost/compress v1.18.0
1213
github.com/leanovate/gopter v0.2.11

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,6 @@ github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJV
558558
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
559559
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
560560
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
561-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250612160538-bf4097d092cb h1:jDoqH/5lFEAscgc6yUYg1SzthHct98z5nUwmuSN5Pq4=
562-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250612160538-bf4097d092cb/go.mod h1:H7gOuN4Jzf+DWllfP5Pb7AiCWBMQrDX1D1KYXAEhdnw=
563-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250620171839-6009cad95977 h1:7Rn14H77o9OmnsWU75FWkJjQ6JXvTBSu7vGWQ3D+Nrg=
564-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250620171839-6009cad95977/go.mod h1:crejZI9ZpBHfhqghQOG9u7Sri7CBzEUYQ/0lVnN60yg=
565561
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250623140116-9cb7ec4a4def h1:83rS5GM53zm0G8eIfTtxBK5o8YRZf5bDoku98E/noks=
566562
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250623140116-9cb7ec4a4def/go.mod h1:crejZI9ZpBHfhqghQOG9u7Sri7CBzEUYQ/0lVnN60yg=
567563
github.com/smartcontractkit/freeport v0.1.1 h1:B5fhEtmgomdIhw03uPVbVTP6oPv27fBhZsoZZMSIS8I=

llo/json_report_codec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package llo
22

33
import (
44
"encoding/hex"
5-
"encoding/json"
65
"errors"
76
"fmt"
87

8+
"github.com/goccy/go-json"
9+
910
"github.com/smartcontractkit/libocr/offchainreporting2/types"
1011
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2/types"
1112

llo/json_report_codec_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ func Test_JSONCodec(t *testing.T) {
325325
cdc := JSONReportCodec{}
326326

327327
_, err := cdc.Pack(digest, seqNr, report, sigs)
328-
require.EqualError(t, err, "json: error calling MarshalJSON for type json.RawMessage: invalid character 'o' in literal false (expecting 'a')")
328+
require.Error(t, err)
329+
require.Contains(t, err.Error(), "json: error calling MarshalJSON for type json.RawMessage")
329330
})
330331
t.Run("report is valid JSON", func(t *testing.T) {
331332
digest := types.ConfigDigest([32]byte{1, 2, 3})

llo/reportcodecs/evm/report_codec_common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package evm
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"math"
76
"math/big"
87
"regexp"
98
"strconv"
109

10+
"github.com/goccy/go-json"
11+
1112
"github.com/shopspring/decimal"
1213

1314
llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo"

llo/reportcodecs/evm/report_codec_common_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package evm
22

33
import (
44
"encoding/hex"
5-
"encoding/json"
65
"fmt"
76
"math"
87
"math/big"
98
"testing"
109

10+
"github.com/goccy/go-json"
11+
1112
"github.com/shopspring/decimal"
1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"

llo/reportcodecs/evm/report_codec_evm_abi_encode_unpacked.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package evm
22

33
import (
44
"bytes"
5-
"encoding/json"
65
"errors"
76
"fmt"
87
"math/big"
98

9+
"github.com/goccy/go-json"
10+
1011
"github.com/ethereum/go-ethereum/accounts/abi"
1112
"github.com/ethereum/go-ethereum/common"
1213
"github.com/shopspring/decimal"

llo/reportcodecs/evm/report_codec_evm_abi_encode_unpacked_expr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func TestReportCodecEVMABIEncodeUnpackedExpr_Verify(t *testing.T) {
201201
}
202202
err := c.Verify(cd)
203203
require.Error(t, err)
204-
require.EqualError(t, err, "invalid Opts, got: \"\\\"invalid\\\"\"; json: cannot unmarshal string into Go value of type evm.ReportFormatEVMABIEncodeOpts")
204+
require.Contains(t, err.Error(), "invalid character")
205205
})
206206
t.Run("negative BaseUSDFee", func(t *testing.T) {
207207
cd := llotypes.ChannelDefinition{

llo/reportcodecs/evm/report_codec_evm_abi_encode_unpacked_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ func TestReportCodecEVMABIEncodeUnpacked_Verify(t *testing.T) {
704704
}
705705
err := c.Verify(cd)
706706
require.Error(t, err)
707-
require.EqualError(t, err, "invalid Opts, got: \"\\\"invalid\\\"\"; json: cannot unmarshal string into Go value of type evm.ReportFormatEVMABIEncodeOpts")
707+
require.Contains(t, err.Error(), "invalid Opts, got: \"\\\"invalid\\\"\"")
708708
})
709709
t.Run("negative BaseUSDFee", func(t *testing.T) {
710710
cd := llotypes.ChannelDefinition{

llo/reportcodecs/evm/report_codec_evm_streamlined.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package evm
33
import (
44
"bytes"
55
"encoding/binary"
6-
"encoding/json"
76
"fmt"
87
"math"
98

9+
"github.com/goccy/go-json"
10+
1011
"github.com/ethereum/go-ethereum/common"
1112
"github.com/smartcontractkit/libocr/offchainreporting2/types"
1213
"google.golang.org/protobuf/proto"

0 commit comments

Comments
 (0)