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

encoding/json: Add custom JSON package with build tag support for Sonic #1623

Merged
merged 49 commits into from
Feb 20, 2025
Merged
Changes from 28 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8333e5c
tag optional sonic and allow full library conversion
Aug 20, 2024
c47137c
Add workflow and disallow arm and darwin usage
Aug 20, 2024
6e24f60
Add basic hotswap benchmark
Aug 20, 2024
b70b9e7
linter: fix
Aug 20, 2024
84dd409
use bash
Aug 20, 2024
711db77
linter: fix?
Aug 20, 2024
223f786
Fix whoopsie, add to make file, also add mention in features list.
Aug 20, 2024
9a72688
Merge branch 'master' into encoding_swap
Aug 24, 2024
2f69362
Merge branch 'master' into encoding_swap
Sep 2, 2024
79c85c9
Merge branch 'master' into encoding_swap
Sep 13, 2024
b4f0243
Merge branch 'master' into encoding_swap
Sep 13, 2024
417e0aa
Merge branch 'master' into encoding_swap
Sep 15, 2024
83f1d57
Merge branch 'master' into encoding_swap
Oct 2, 2024
f2d56cf
Merge branch 'master' into encoding_swap
Oct 10, 2024
7bd7cc4
Merge branch 'master' into encoding_swap
Oct 23, 2024
79ebfa1
Merge branch 'master' into encoding_swap
Nov 11, 2024
6b6fb5e
test enforcement
Nov 11, 2024
ac47cc6
actually read documentation see if this works
Nov 11, 2024
135e2b6
linter: fix
Nov 11, 2024
2d08549
Merge branch 'master' into encoding_swap
Nov 25, 2024
1a82764
Merge branch 'master' into encoding_swap
Jan 8, 2025
1ca8eaa
linter: fix
Jan 8, 2025
ab5fd01
sonic: bump tagged version
Jan 10, 2025
1697977
encoding/json: drop build tag arch and os filters
Jan 10, 2025
3905b62
encoding/json: consolidate tests
Jan 10, 2025
1c9f9c2
encoding/json: log build tag usage
Jan 10, 2025
4f8e487
Merge branch 'master' into encoding_swap
Jan 13, 2025
9cffc8f
rm superfluous builds
Jan 13, 2025
1b15e4c
glorious/nits: add template change and regen docs
Jan 28, 2025
a7ac15d
glorious/nits: update commentary on nolint directive
Jan 28, 2025
f23f3c3
glorious/nits: rm init func and log results in main.go
Jan 28, 2025
fba5316
Test to actually pull flag in
Jan 28, 2025
880cd37
Merge branch 'master' into encoding_swap
Feb 2, 2025
dde84c7
Merge branch 'master' into encoding_swap
Feb 11, 2025
c936252
linter: fix
Feb 11, 2025
a843b58
thrasher: nits
Feb 12, 2025
09bac6c
gk: nits 4 goflags goooooooooo!
Feb 13, 2025
a9ce5aa
gk: nits rn
Feb 14, 2025
625ae13
Merge branch 'master' into encoding_swap
Feb 19, 2025
9fff614
make sonic default json implementation
Feb 19, 2025
b8a5070
screen 386
Feb 19, 2025
9a52e19
linter: fix
Feb 20, 2025
9c154ca
Add commentary
Feb 20, 2025
ce01376
glorious: nits Makefile not working
Feb 20, 2025
fcc0b27
gk: nits
Feb 20, 2025
d49cf8e
gk: nits whoops
Feb 20, 2025
ad20589
whoopsirino
Feb 20, 2025
c1f1216
mention 32bit systems won't be sonic
Feb 20, 2025
00ebc20
gk: super-duper nit of extremes
Feb 20, 2025
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
24 changes: 21 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -13,22 +13,32 @@ jobs:
goarch: amd64
psql: true
skip_wrapper_tests: false
sonic: false
- os: ubuntu-latest
goarch: 386
psql: true
skip_wrapper_tests: true
sonic: false
- os: macos-latest
goarch: amd64
psql: true
skip_wrapper_tests: true
sonic: false
- os: macos-13 # beta
goarch: amd64
psql: true
skip_wrapper_tests: true
sonic: false
- os: windows-latest
goarch: amd64
psql: true
skip_wrapper_tests: true
sonic: false
- os: ubuntu-latest
goarch: amd64
psql: true
skip_wrapper_tests: false
sonic: true

runs-on: ${{ matrix.os }}

@@ -84,13 +94,21 @@ jobs:
echo "CGO_ENABLED=1" >> $GITHUB_ENV
shell: bash

- name: Set test flags
run: |
TEST_FLAGS=""
if [ "${{ matrix.sonic }}" = "true" ]; then
TEST_FLAGS="-tags sonic"
fi
shell: bash

- name: Test
run: | # PGSERVICEFILE isn't supported by lib/pq and will cause a panic if set
unset PGSERVICEFILE
if [ "${{ matrix.goarch }}" = "386" ]; then
go test -coverprofile coverage.txt -covermode atomic ./...
go test $TEST_FLAGS -coverprofile coverage.txt -covermode atomic ./...
else
go test -race -coverprofile coverage.txt -covermode atomic ./...
go test $TEST_FLAGS -race -coverprofile coverage.txt -covermode atomic ./...
fi
shell: bash
env:
@@ -169,4 +187,4 @@ jobs:
cd web/
npm install
npm run lint
npm run build
npm run build
14 changes: 12 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ linters:
- copyloopvar
# - cyclop
- decorder
# - depguard
- depguard
- dogsled
# - dupl
- dupword
@@ -117,6 +117,17 @@ linters:
# - zerologlint

linters-settings:
depguard:
rules:
prevent_json_package_use:
list-mode: lax # allow unless explicitely denied
files:
- $all
allow:
- github.com/thrasher-corp/gocryptotrader/encoding/json
deny:
- pkg: encoding/json
desc: "Please use the custom JSON package github.com/thrasher-corp/gocryptotrader/encoding/json instead of encoding/json to allow sonic/json switching."
govet:
enable:
- shadow
@@ -141,7 +152,6 @@ linters-settings:
- float-compare
# We deliberately use Equal over Len to avoid spamming the contents of large Slices
- len

issues:
max-issues-per-linter: 0
max-same-issues: 0
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -78,3 +78,7 @@ endef
check-jq:
@printf "Checking if jq is installed... "
@command -v jq >/dev/null 2>&1 && { printf "OK\n"; } || { printf "FAILED. Please install jq to proceed.\n"; exit 1; }

.PHONY: sonic
sonic:
go build -tags=sonic ./...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from all previous examples.
You're not building sonic. You're building gct with sonic.
And it leaves a gap where install should be.

I suggest that users need to use make build and install with an argument:

make install JSON=sonic

Or, if we go the route I'm proposing:

make install JSON=golang

Also: Given the recent highlighting of act, I wonder if we remove Makefile and update docs to use act, and make that a (non-runtime) dependency for installing GCT from source.
Note: As we approach semver (right?), we should be issuing binaries anyway

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to allow customisation, I think a more general approach make build FLAGS="-tags=sonic" might be better. This gives users the flexibility to specify any build tags or flags they need without hardcoding specific options in the Makefile. If users have to manually specify flags every time, they might as well use go build or go install directly. The goal of make is to simplify workflows, not add unnecessary complexity.

We could:

Keep the Makefile but allow FLAGS to be overridden for advanced use cases.
Provide default targets like make build-sonic for common configurations.

As for act that is an option. But I have little to no experience in semver and issuing binaries so you can discuss with @thrasher- && @gloriousCode

Copy link
Collaborator

@gbjk gbjk Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to use FLAGS, then:

GOFLAGS="-tags=hedgehogless" make build

makes more sense than adding it to the end, and means no extra support for FLAGS in Makefile.
( Note: I'll accept nosonic or sonicless )

act: I've only just started using it

Semver is a separate topic, and issuing binaries doesn't need to be related to it, now that I think about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can keep the Makefile, as I find other recipes useful locally like pprof and only use act for simulating GHA workflows which I don't think it can do that also. We also want to keep the number of dependencies (runtime and non-runtime) down as much as possible for GCT ouf of the box.
  2. I'm happy with supporting both options who want a quick shorthand recipe and make install/make build param for power users (we do this with LTC where things are diisabled by NO_X).

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@ However, we welcome pull requests for any exchange which does not match this cri
+ WebGUI (discontinued).
+ Exchange HTTP mock testing. See [mock](/exchanges/mock/README.md).
+ Exchange multichain deposits and withdrawals for specific exchanges. See [multichain transfer support](/docs/MULTICHAIN_TRANSFER_SUPPORT.md).
+ **Sonic JSON Integration**: Swap between the default Go 'encoding/json' package and the sonic library using go build tags for optimized JSON handling `-tags=sonic` or by using the make file `make sonic`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep styling in line with the others (or update the others) and update the template as well.


## Development Tracking

2 changes: 1 addition & 1 deletion backtester/btcli/main.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
@@ -13,6 +12,7 @@ import (

"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/gctrpc/auth"
"github.com/thrasher-corp/gocryptotrader/signaler"
"github.com/urfave/cli/v2"
2 changes: 1 addition & 1 deletion backtester/config/backtesterconfig.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package config

import (
"encoding/json"
"fmt"
"os"
"path/filepath"

"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
gctconfig "github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
)

// ReadBacktesterConfigFromPath will take a config from a path
2 changes: 1 addition & 1 deletion backtester/config/batcktesterconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

import (
"encoding/json"
"errors"
"path/filepath"
"testing"

"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
)

func TestLoadBacktesterConfig(t *testing.T) {
2 changes: 1 addition & 1 deletion backtester/config/strategyconfig.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"encoding/json"
"fmt"
"os"
"strings"
@@ -13,6 +12,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/base"
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/log"
)
2 changes: 1 addition & 1 deletion backtester/config/strategyconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"encoding/json"
"errors"
"os"
"path/filepath"
@@ -17,6 +16,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
2 changes: 1 addition & 1 deletion backtester/config/strategyconfigbuilder/main.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package main

import (
"bufio"
"encoding/json"
"errors"
"fmt"
"log"
@@ -23,6 +22,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/database"
dbPSQL "github.com/thrasher-corp/gocryptotrader/database/drivers/postgres"
dbsqlite3 "github.com/thrasher-corp/gocryptotrader/database/drivers/sqlite3"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
gctkline "github.com/thrasher-corp/gocryptotrader/exchanges/kline"
)
2 changes: 1 addition & 1 deletion backtester/eventhandlers/statistics/statistics.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package statistics

import (
"encoding/json"
"fmt"
"time"

@@ -17,6 +16,7 @@ import (
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/log"
)

2 changes: 1 addition & 1 deletion backtester/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"net/http"
@@ -15,6 +14,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/plugins/strategies"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/engine"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/signaler"
2 changes: 1 addition & 1 deletion cmd/apichecker/apicheck.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
@@ -18,6 +17,7 @@ import (

"github.com/thrasher-corp/gocryptotrader/common"
gctfile "github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/log"
2 changes: 1 addition & 1 deletion cmd/apichecker/apicheck_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"encoding/json"
"os"
"reflect"
"testing"

gctfile "github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/log"
)
2 changes: 1 addition & 1 deletion cmd/config_builder/builder.go
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@ package main

import (
"context"
"encoding/json"
"log"
"sync"

"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/engine"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
)
2 changes: 1 addition & 1 deletion cmd/documentation/documentation.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
@@ -17,6 +16,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
4 changes: 2 additions & 2 deletions cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
@@ -19,6 +18,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/engine"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
@@ -1028,7 +1028,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}

func jsonifyInterface(params []interface{}) json.RawMessage {
response, _ := json.MarshalIndent(params, "", " ") //nolint:errchkjson // TODO: ignore this for now
response, _ := json.MarshalIndent(params, "", " ")
return response
}

3 changes: 1 addition & 2 deletions cmd/exchange_wrapper_issues/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main

import (
"encoding/json"

"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
)

2 changes: 1 addition & 1 deletion cmd/gctcli/main.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
@@ -12,6 +11,7 @@ import (

"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/gctrpc/auth"
"github.com/thrasher-corp/gocryptotrader/signaler"
2 changes: 1 addition & 1 deletion cmd/gen_sqlboiler_config/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"os"
@@ -12,6 +11,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/repository"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
)

var (
2 changes: 1 addition & 1 deletion cmd/websocket_client/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"log"
@@ -13,6 +12,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
)

Loading