Revert "Use jsoniteer for faster json encoding/decoding"

This reverts commit 4233b87b89.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2018-01-29 15:47:48 -05:00
parent c6a7d10568
commit d179c61231
11 changed files with 11 additions and 33 deletions

View File

@ -2,6 +2,7 @@ package containerd
import ( import (
"context" "context"
"encoding/json"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -13,7 +14,6 @@ import (
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
prototypes "github.com/gogo/protobuf/types" prototypes "github.com/gogo/protobuf/types"
jsoniter "github.com/json-iterator/go"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -115,7 +115,6 @@ func (c *container) Spec(ctx context.Context) (*specs.Spec, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
var s specs.Spec var s specs.Spec
if err := json.Unmarshal(r.Spec.Value, &s); err != nil { if err := json.Unmarshal(r.Spec.Value, &s); err != nil {
return nil, err return nil, err

View File

@ -4,6 +4,7 @@ package containerd
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -19,7 +20,6 @@ import (
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types" protobuf "github.com/gogo/protobuf/types"
jsoniter "github.com/json-iterator/go"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/identity" "github.com/opencontainers/image-spec/identity"
"github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/image-spec/specs-go/v1"
@ -121,7 +121,6 @@ func decodeIndex(ctx context.Context, store content.Store, id digest.Digest) (*v
if err != nil { if err != nil {
return nil, err return nil, err
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(p, &index); err != nil { if err := json.Unmarshal(p, &index); err != nil {
return nil, err return nil, err
} }

View File

@ -4,12 +4,12 @@ package seccomp
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/oci" "github.com/containerd/containerd/oci"
jsoniter "github.com/json-iterator/go"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
) )
@ -23,7 +23,6 @@ func WithProfile(profile string) oci.SpecOpts {
if err != nil { if err != nil {
return fmt.Errorf("Cannot load seccomp profile %q: %v", profile, err) return fmt.Errorf("Cannot load seccomp profile %q: %v", profile, err)
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(f, s.Linux.Seccomp); err != nil { if err := json.Unmarshal(f, s.Linux.Seccomp); err != nil {
return fmt.Errorf("Decoding seccomp profile failed %q: %v", profile, err) return fmt.Errorf("Decoding seccomp profile failed %q: %v", profile, err)
} }

View File

@ -2,6 +2,7 @@ package images
import ( import (
"context" "context"
"encoding/json"
"strings" "strings"
"time" "time"
@ -9,7 +10,6 @@ import (
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
jsoniter "github.com/json-iterator/go"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -123,7 +123,6 @@ func Manifest(ctx context.Context, provider content.Provider, image ocispec.Desc
return ocispec.Manifest{}, err return ocispec.Manifest{}, err
} }
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
if err := Walk(ctx, HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { if err := Walk(ctx, HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
switch desc.MediaType { switch desc.MediaType {
@ -217,7 +216,6 @@ func Config(ctx context.Context, provider content.Provider, image ocispec.Descri
// Platforms returns one or more platforms supported by the image. // Platforms returns one or more platforms supported by the image.
func Platforms(ctx context.Context, provider content.Provider, image ocispec.Descriptor) ([]ocispec.Platform, error) { func Platforms(ctx context.Context, provider content.Provider, image ocispec.Descriptor) ([]ocispec.Platform, error) {
var platformSpecs []ocispec.Platform var platformSpecs []ocispec.Platform
json := jsoniter.ConfigCompatibleWithStandardLibrary
return platformSpecs, Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { return platformSpecs, Walk(ctx, Handlers(HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
if desc.Platform != nil { if desc.Platform != nil {
platformSpecs = append(platformSpecs, *desc.Platform) platformSpecs = append(platformSpecs, *desc.Platform)
@ -288,7 +286,6 @@ func Check(ctx context.Context, provider content.Provider, image ocispec.Descrip
// Children returns the immediate children of content described by the descriptor. // Children returns the immediate children of content described by the descriptor.
func Children(ctx context.Context, provider content.Provider, desc ocispec.Descriptor, platform string) ([]ocispec.Descriptor, error) { func Children(ctx context.Context, provider content.Provider, desc ocispec.Descriptor, platform string) ([]ocispec.Descriptor, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var descs []ocispec.Descriptor var descs []ocispec.Descriptor
switch desc.MediaType { switch desc.MediaType {
case MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest: case MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
@ -357,7 +354,6 @@ func RootFS(ctx context.Context, provider content.Provider, configDesc ocispec.D
return nil, err return nil, err
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
var config ocispec.Image var config ocispec.Image
if err := json.Unmarshal(p, &config); err != nil { if err := json.Unmarshal(p, &config); err != nil {
return nil, err return nil, err

View File

@ -3,13 +3,13 @@ package oci
import ( import (
"archive/tar" "archive/tar"
"context" "context"
"encoding/json"
"io" "io"
"sort" "sort"
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
jsoniter "github.com/json-iterator/go"
ocispecs "github.com/opencontainers/image-spec/specs-go" ocispecs "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -116,8 +116,6 @@ func ociLayoutFile(version string) tarRecord {
Version: version, Version: version,
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
b, err := json.Marshal(layout) b, err := json.Marshal(layout)
if err != nil { if err != nil {
panic(err) panic(err)
@ -146,7 +144,6 @@ func ociIndexRecord(manifests ...ocispec.Descriptor) tarRecord {
Manifests: manifests, Manifests: manifests,
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
b, err := json.Marshal(index) b, err := json.Marshal(index)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -4,6 +4,7 @@ package oci
import ( import (
"archive/tar" "archive/tar"
"context" "context"
"encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -13,7 +14,6 @@ import (
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
jsoniter "github.com/json-iterator/go"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -83,7 +83,6 @@ func onUntarIndexJSON(r io.Reader, imageName string) ([]images.Image, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
var idx ocispec.Index var idx ocispec.Index
if err := json.Unmarshal(b, &idx); err != nil { if err := json.Unmarshal(b, &idx); err != nil {
return nil, err return nil, err
@ -132,7 +131,6 @@ func onUntarBlob(ctx context.Context, r io.Reader, store content.Store, name str
// - images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest // - images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest
// - images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex // - images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex
func GetChildrenDescriptors(r io.Reader, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { func GetChildrenDescriptors(r io.Reader, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
switch desc.MediaType { switch desc.MediaType {
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest: case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
var manifest ocispec.Manifest var manifest ocispec.Manifest

View File

@ -4,6 +4,7 @@ package proc
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -21,7 +22,6 @@ import (
runc "github.com/containerd/go-runc" runc "github.com/containerd/go-runc"
"github.com/containerd/typeurl" "github.com/containerd/typeurl"
google_protobuf "github.com/gogo/protobuf/types" google_protobuf "github.com/gogo/protobuf/types"
jsoniter "github.com/json-iterator/go"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -349,7 +349,6 @@ func (p *Init) Runtime() *runc.Runc {
// exec returns a new exec'd process // exec returns a new exec'd process
func (p *Init) exec(context context.Context, path string, r *ExecConfig) (Process, error) { func (p *Init) exec(context context.Context, path string, r *ExecConfig) (Process, error) {
// process exec request // process exec request
json := jsoniter.ConfigCompatibleWithStandardLibrary
var spec specs.Process var spec specs.Process
if err := json.Unmarshal(r.Spec.Value, &spec); err != nil { if err := json.Unmarshal(r.Spec.Value, &spec); err != nil {
return nil, err return nil, err
@ -407,7 +406,6 @@ func (p *Init) checkpoint(context context.Context, r *CheckpointConfig) error {
} }
func (p *Init) update(context context.Context, r *google_protobuf.Any) error { func (p *Init) update(context context.Context, r *google_protobuf.Any) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var resources specs.LinuxResources var resources specs.LinuxResources
if err := json.Unmarshal(r.Value, &resources); err != nil { if err := json.Unmarshal(r.Value, &resources); err != nil {
return err return err

View File

@ -1,11 +1,11 @@
package mount package mount
import ( import (
"encoding/json"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/Microsoft/hcsshim" "github.com/Microsoft/hcsshim"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -49,7 +49,6 @@ const ParentLayerPathsFlag = "parentLayerPaths="
// GetParentPaths of the mount // GetParentPaths of the mount
func (m *Mount) GetParentPaths() ([]string, error) { func (m *Mount) GetParentPaths() ([]string, error) {
var parentLayerPaths []string var parentLayerPaths []string
json := jsoniter.ConfigCompatibleWithStandardLibrary
for _, option := range m.Options { for _, option := range m.Options {
if strings.HasPrefix(option, ParentLayerPathsFlag) { if strings.HasPrefix(option, ParentLayerPathsFlag) {
err := json.Unmarshal([]byte(option[len(ParentLayerPathsFlag):]), &parentLayerPaths) err := json.Unmarshal([]byte(option[len(ParentLayerPathsFlag):]), &parentLayerPaths)

View File

@ -4,6 +4,7 @@ package oci
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -16,7 +17,6 @@ import (
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
jsoniter "github.com/json-iterator/go"
"github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/runc/libcontainer/user" "github.com/opencontainers/runc/libcontainer/user"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
@ -66,7 +66,6 @@ func WithLinuxNamespace(ns specs.LinuxNamespace) SpecOpts {
// WithImageConfig configures the spec to from the configuration of an Image // WithImageConfig configures the spec to from the configuration of an Image
func WithImageConfig(image Image) SpecOpts { func WithImageConfig(image Image) SpecOpts {
return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) error { return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) error {
json := jsoniter.ConfigCompatibleWithStandardLibrary
ic, err := image.Config(ctx) ic, err := image.Config(ctx)
if err != nil { if err != nil {
return err return err

View File

@ -4,12 +4,12 @@ package oci
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"github.com/containerd/containerd/containers" "github.com/containerd/containerd/containers"
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
jsoniter "github.com/json-iterator/go"
"github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
) )
@ -24,7 +24,6 @@ func WithImageConfig(image Image) SpecOpts {
var ( var (
ociimage v1.Image ociimage v1.Image
config v1.ImageConfig config v1.ImageConfig
json = jsoniter.ConfigCompatibleWithStandardLibrary
) )
switch ic.MediaType { switch ic.MediaType {
case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config: case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config:

View File

@ -5,6 +5,7 @@ import (
"compress/gzip" "compress/gzip"
"context" "context"
"encoding/base64" "encoding/base64"
"encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -20,7 +21,6 @@ import (
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes"
jsoniter "github.com/json-iterator/go"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go" specs "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@ -110,7 +110,6 @@ func (c *Converter) Convert(ctx context.Context) (ocispec.Descriptor, error) {
return ocispec.Descriptor{}, errors.Wrap(err, "schema 1 conversion failed") return ocispec.Descriptor{}, errors.Wrap(err, "schema 1 conversion failed")
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
var img ocispec.Image var img ocispec.Image
if err := json.Unmarshal([]byte(c.pulledManifest.History[0].V1Compatibility), &img); err != nil { if err := json.Unmarshal([]byte(c.pulledManifest.History[0].V1Compatibility), &img); err != nil {
return ocispec.Descriptor{}, errors.Wrap(err, "failed to unmarshal image from schema 1 history") return ocispec.Descriptor{}, errors.Wrap(err, "failed to unmarshal image from schema 1 history")
@ -195,7 +194,6 @@ func (c *Converter) fetchManifest(ctx context.Context, desc ocispec.Descriptor)
return err return err
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
var m manifest var m manifest
if err := json.Unmarshal(b, &m); err != nil { if err := json.Unmarshal(b, &m); err != nil {
return err return err
@ -318,7 +316,6 @@ func (c *Converter) schema1ManifestHistory() ([]ocispec.History, []digest.Digest
return nil, nil, errors.New("no history") return nil, nil, errors.New("no history")
} }
json := jsoniter.ConfigCompatibleWithStandardLibrary
history := make([]ocispec.History, len(m.History)) history := make([]ocispec.History, len(m.History))
diffIDs := []digest.Digest{} diffIDs := []digest.Digest{}
for i := range m.History { for i := range m.History {
@ -376,7 +373,6 @@ type v1History struct {
// empty layer. A return value of true indicates the layer is empty, // empty layer. A return value of true indicates the layer is empty,
// however false does not indicate non-empty. // however false does not indicate non-empty.
func isEmptyLayer(compatHistory []byte) (bool, error) { func isEmptyLayer(compatHistory []byte) (bool, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var h v1History var h v1History
if err := json.Unmarshal(compatHistory, &h); err != nil { if err := json.Unmarshal(compatHistory, &h); err != nil {
return false, err return false, err
@ -426,7 +422,6 @@ func joseBase64UrlDecode(s string) ([]byte, error) {
} }
func stripSignature(b []byte) ([]byte, error) { func stripSignature(b []byte) ([]byte, error) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
var sig signature var sig signature
if err := json.Unmarshal(b, &sig); err != nil { if err := json.Unmarshal(b, &sig); err != nil {
return nil, err return nil, err