feat(json): improve JSON performance with bytedance/sonic

This commit is contained in:
yusing
2025-09-29 17:43:34 +08:00
parent 024100aa8c
commit f411e17d80
29 changed files with 86 additions and 78 deletions

View File

@@ -1,8 +1,7 @@
package types
import (
"encoding/json"
"github.com/bytedance/sonic"
"github.com/docker/docker/api/types/container"
"github.com/yusing/ds/ordered"
"github.com/yusing/godoxy/agent/pkg/agent"
@@ -79,5 +78,5 @@ func (e *ContainerError) Unwrap() error {
func (e *ContainerError) MarshalJSON() ([]byte, error) {
err := e.errs.Error().(interface{ Plain() []byte })
return json.Marshal(string(err.Plain()))
return sonic.Marshal(string(err.Plain()))
}

View File

@@ -7,6 +7,7 @@ import (
"strconv"
"time"
"github.com/bytedance/sonic"
strutils "github.com/yusing/goutils/strings"
"github.com/yusing/goutils/task"
)
@@ -145,7 +146,7 @@ func (s HealthStatus) MarshalJSON() ([]byte, error) {
func (s *HealthStatus) UnmarshalJSON(data []byte) error {
var v any
if err := json.Unmarshal(data, &v); err != nil {
if err := sonic.Unmarshal(data, &v); err != nil {
return err
}
switch v := v.(type) {
@@ -169,7 +170,7 @@ func (jsonRepr *HealthJSONRepr) MarshalJSON() ([]byte, error) {
if url == "http://:0" {
url = ""
}
return json.Marshal(HealthJSON{
return sonic.Marshal(HealthJSON{
Name: jsonRepr.Name,
Config: jsonRepr.Config,
Started: jsonRepr.Started.Unix(),