encoding/json: Add custom JSON package with build tag support for Sonic#1623
encoding/json: Add custom JSON package with build tag support for Sonic#1623thrasher- merged 49 commits intothrasher-corp:masterfrom
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1623 +/- ##
=======================================
Coverage 37.07% 37.07%
=======================================
Files 414 414
Lines 180274 180274
=======================================
+ Hits 66835 66845 +10
- Misses 105574 105577 +3
+ Partials 7865 7852 -13
|
|
Flagged this as medium because this is beast. Sorry for those that cant use it. 🙏 |
Ok cool,
I guess it comes from GCT library (as the more we update this library the further it drifts away from this and I could be completely wrong) wants to be as close to using internal dependencies as much as possible as default and all external dependencies are opt in. You're right in that this approach is being too cautious but I like that. Also it had to do with sonics different configurations Default, Fastest, Standard(aligns most closely to encoding/json). I was thinking we could have different build tags for those in future if I or somebody else ever gets around to it (other things are way more priority). Also we could hot swap in different JSON libraries if they were similar if they provide a certain use case. Anyways this is my perspective and I am not against sonic being default either. @thrasher- @gloriousCode for your input |
gbjk
left a comment
There was a problem hiding this comment.
Looks good 👍 Great work 🎉
Only suggests again.
gbjk
left a comment
There was a problem hiding this comment.
Looks good.
If you take the suggestion to make sonic the default, then I'll re-review that, obviously.
We can default sonic to on, since we're already using another json package jsonparser by default in many exchanges and other systems now. |
gbjk
left a comment
There was a problem hiding this comment.
Great work 🎉
Only a couple of minor things.
encoding/json/json.go
Outdated
| package json | ||
|
|
||
| import "encoding/json" //nolint:depguard // This is a wrapper package for encoding/json. It serves as the default JSON package for GCT (GoCryptoTrader). All uses of JSON throughout the application should refer to this package with the default build. | ||
| import "encoding/json" //nolint:depguard // This is a wrapper package for encoding/json. All uses of JSON throughout the application should refer to this when sonic_off build tag is used. |
There was a problem hiding this comment.
- Seems like we're using the nolint as the package comment across the 3 json/*.go files.
encoding/jsonis ambiguous in the comment, since it's referring togolang.org/encoding/jsonbut insidegct/encoding/json- I don't think we need to say that all uses of json throughout should refer to it
So I think we want a single package comment (common.go?) and then package comments in the other two relevant to them, and then the depguard nolint comment just explains it:
// json is an abstraction middleware package to allow switching between json encoder/decoder implementations
// The default implementation is sonic.
// Build with `sonic_off` or `386` tags to switch to golang.org/encoding/json.
and
import "encoding/json" //nolint:depguard // Acceptable use in gct json wrapper
30f0150 to
ad20589
Compare
README.md
Outdated
| + Pull requests need to be based on and opened against the `master` branch. | ||
|
|
||
| ## Compiling instructions | ||
| ## Compilation and run instructions |
There was a problem hiding this comment.
Super-Duper Nit: "Compilation" tastes weird
Compiling and Running
There was a problem hiding this comment.
Considered also splitting sections into Compiling and Running
|
Just a note here: |
PR Description
This pull request introduces a custom JSON package located in encoding/json/ to facilitate swapping between the default Go encoding/json package and the sonic library based on build tags.
Adds:
Import Updates:
All imports to the standard encoding/json package have been updated to the new custom package github.com/thrasher-corp/gocryptotrader/encoding/json.
Added basic benchmarks for both the default encoding/json and the sonic implementation to evaluate hot-swap performance.
Type of change
Please delete options that are not relevant and add an
xin[]as item is complete.How has this been tested
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.
Checklist