use json unmarshal/marshal from jsoniter in hotpaths (#12269)

This commit is contained in:
Harshavardhana 2021-05-11 02:02:32 -07:00 committed by GitHub
parent 14849b9b2c
commit b81fada834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 16 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import (
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go" "github.com/minio/madmin-go"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
iampolicy "github.com/minio/minio/pkg/iam/policy" iampolicy "github.com/minio/minio/pkg/iam/policy"
@ -154,6 +155,7 @@ func (a adminAPIHandlers) SetRemoteTargetHandler(w http.ResponseWriter, r *http.
return return
} }
var target madmin.BucketTarget var target madmin.BucketTarget
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err = json.Unmarshal(reqBytes, &target); err != nil { if err = json.Unmarshal(reqBytes, &target); err != nil {
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErrWithErr(ErrAdminConfigBadJSON, err), r.URL) writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErrWithErr(ErrAdminConfigBadJSON, err), r.URL)
return return

View File

@ -21,11 +21,11 @@ import (
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"encoding/json"
"net/http" "net/http"
"sync" "sync"
"time" "time"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go" "github.com/minio/madmin-go"
minio "github.com/minio/minio-go/v7" minio "github.com/minio/minio-go/v7"
miniogo "github.com/minio/minio-go/v7" miniogo "github.com/minio/minio-go/v7"
@ -386,6 +386,7 @@ func parseBucketTargetConfig(bucket string, cdata, cmetadata []byte) (*madmin.Bu
return nil, nil return nil, nil
} }
data = cdata data = cdata
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if len(cmetadata) != 0 { if len(cmetadata) != 0 {
if err := json.Unmarshal(cmetadata, &meta); err != nil { if err := json.Unmarshal(cmetadata, &meta); err != nil {
return nil, err return nil, err

View File

@ -21,11 +21,11 @@ import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"encoding/binary" "encoding/binary"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
jsoniter "github.com/json-iterator/go"
"github.com/minio/minio/pkg/fips" "github.com/minio/minio/pkg/fips"
"github.com/minio/minio/pkg/kms" "github.com/minio/minio/pkg/kms"
"github.com/secure-io/sio-go" "github.com/secure-io/sio-go"
@ -88,6 +88,7 @@ func Encrypt(KMS kms.KMS, plaintext io.Reader, context kms.Context) (io.Reader,
header [5]byte header [5]byte
buffer bytes.Buffer buffer bytes.Buffer
) )
var json = jsoniter.ConfigCompatibleWithStandardLibrary
metadata, err := json.Marshal(encryptedObject{ metadata, err := json.Marshal(encryptedObject{
KeyID: key.KeyID, KeyID: key.KeyID,
KMSKey: key.Ciphertext, KMSKey: key.Ciphertext,
@ -139,6 +140,7 @@ func Decrypt(KMS kms.KMS, ciphertext io.Reader, context kms.Context) (io.Reader,
if _, err := io.ReadFull(ciphertext, metadataBuffer); err != nil { if _, err := io.ReadFull(ciphertext, metadataBuffer); err != nil {
return nil, err return nil, err
} }
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(metadataBuffer, &metadata); err != nil { if err := json.Unmarshal(metadataBuffer, &metadata); err != nil {
return nil, err return nil, err
} }

View File

@ -20,7 +20,6 @@ package cmd
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/json"
"net/http" "net/http"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
@ -41,6 +40,7 @@ const (
// storeDataUsageInBackend will store all objects sent on the gui channel until closed. // storeDataUsageInBackend will store all objects sent on the gui channel until closed.
func storeDataUsageInBackend(ctx context.Context, objAPI ObjectLayer, dui <-chan madmin.DataUsageInfo) { func storeDataUsageInBackend(ctx context.Context, objAPI ObjectLayer, dui <-chan madmin.DataUsageInfo) {
for dataUsageInfo := range dui { for dataUsageInfo := range dui {
var json = jsoniter.ConfigCompatibleWithStandardLibrary
dataUsageJSON, err := json.Marshal(dataUsageInfo) dataUsageJSON, err := json.Marshal(dataUsageInfo)
if err != nil { if err != nil {
logger.LogIf(ctx, err) logger.LogIf(ctx, err)

View File

@ -29,6 +29,7 @@ import (
"unicode/utf8" "unicode/utf8"
jwtgo "github.com/dgrijalva/jwt-go" jwtgo "github.com/dgrijalva/jwt-go"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go" "github.com/minio/madmin-go"
"github.com/minio/minio-go/v7/pkg/set" "github.com/minio/minio-go/v7/pkg/set"
"github.com/minio/minio/cmd/config" "github.com/minio/minio/cmd/config"
@ -124,6 +125,7 @@ func getIAMConfig(item interface{}, data []byte, itemPath string) error {
} }
} }
} }
var json = jsoniter.ConfigCompatibleWithStandardLibrary
return json.Unmarshal(data, item) return json.Unmarshal(data, item)
} }

View File

@ -28,6 +28,7 @@ import (
"time" "time"
"unicode/utf8" "unicode/utf8"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go" "github.com/minio/madmin-go"
"github.com/minio/minio/cmd/config" "github.com/minio/minio/cmd/config"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
@ -244,6 +245,7 @@ func (iamOS *IAMObjectStore) loadIAMConfig(ctx context.Context, item interface{}
} }
} }
} }
var json = jsoniter.ConfigCompatibleWithStandardLibrary
return json.Unmarshal(data, item) return json.Unmarshal(data, item)
} }

View File

@ -26,7 +26,6 @@ import (
"crypto" "crypto"
"crypto/hmac" "crypto/hmac"
"encoding/base64" "encoding/base64"
"encoding/json"
"fmt" "fmt"
"strings" "strings"
"sync" "sync"
@ -188,6 +187,7 @@ func (c *MapClaims) Map() map[string]interface{} {
// MarshalJSON marshals the MapClaims struct // MarshalJSON marshals the MapClaims struct
func (c *MapClaims) MarshalJSON() ([]byte, error) { func (c *MapClaims) MarshalJSON() ([]byte, error) {
var json = jsoniter.ConfigCompatibleWithStandardLibrary
return json.Marshal(c.MapClaims) return json.Marshal(c.MapClaims)
} }

View File

@ -23,6 +23,7 @@ import (
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/minio/madmin-go" "github.com/minio/madmin-go"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
iampolicy "github.com/minio/minio/pkg/iam/policy" iampolicy "github.com/minio/minio/pkg/iam/policy"
@ -85,6 +86,7 @@ func (api adminAPIHandlers) AddTierHandler(w http.ResponseWriter, r *http.Reques
} }
var cfg madmin.TierConfig var cfg madmin.TierConfig
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(reqBytes, &cfg); err != nil { if err := json.Unmarshal(reqBytes, &cfg); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return return
@ -164,6 +166,7 @@ func (api adminAPIHandlers) EditTierHandler(w http.ResponseWriter, r *http.Reque
} }
var creds madmin.TierCreds var creds madmin.TierCreds
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(reqBytes, &creds); err != nil { if err := json.Unmarshal(reqBytes, &creds); err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return return