mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
perf(json): replace encoding/json with bytedance/sonic
Migrate all JSON marshaling and unmarshaling operations to use github.com/bytedance/sonic for improved performance. This affects adapters, middleware, proxy handlers, and the sync store.
This commit is contained in:
@@ -2,10 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/ez-api/ez-api/internal/model"
|
||||
"github.com/ez-api/ez-api/internal/util"
|
||||
"github.com/redis/go-redis/v9"
|
||||
@@ -189,7 +189,7 @@ func (s *SyncService) SyncAll(db *gorm.DB) error {
|
||||
Group: group,
|
||||
Models: models,
|
||||
}
|
||||
payload, err := json.Marshal(snap)
|
||||
payload, err := sonic.Marshal(snap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal provider %d: %w", p.ID, err)
|
||||
}
|
||||
@@ -242,7 +242,7 @@ func (s *SyncService) SyncAll(db *gorm.DB) error {
|
||||
SupportsFIM: m.SupportsFIM,
|
||||
MaxOutputTokens: m.MaxOutputTokens,
|
||||
}
|
||||
payload, err := json.Marshal(snap)
|
||||
payload, err := sonic.Marshal(snap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal model %s: %w", m.Name, err)
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func (s *SyncService) SyncAll(db *gorm.DB) error {
|
||||
}
|
||||
|
||||
func (s *SyncService) hsetJSON(ctx context.Context, key, field string, val interface{}) error {
|
||||
payload, err := json.Marshal(val)
|
||||
payload, err := sonic.Marshal(val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal %s:%s: %w", key, field, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user