From 970e4da4c6636b835175dc79a7492d22dc11ba33 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Tue, 4 Sep 2018 13:13:00 -0400 Subject: [PATCH] Update reflect2 to 1.0.1 (memory utilization fix) Picking up https://github.com/modern-go/reflect2/pull/2 which lazy initializes a map of all types which we don't use in k8s, saving memory & initialization time. --- Godeps/Godeps.json | 4 ++-- staging/src/k8s.io/api/Godeps/Godeps.json | 2 +- .../apiextensions-apiserver/Godeps/Godeps.json | 2 +- .../src/k8s.io/apimachinery/Godeps/Godeps.json | 2 +- staging/src/k8s.io/apiserver/Godeps/Godeps.json | 2 +- .../src/k8s.io/cli-runtime/Godeps/Godeps.json | 2 +- staging/src/k8s.io/client-go/Godeps/Godeps.json | 2 +- staging/src/k8s.io/csi-api/Godeps/Godeps.json | 2 +- .../k8s.io/kube-aggregator/Godeps/Godeps.json | 2 +- staging/src/k8s.io/metrics/Godeps/Godeps.json | 2 +- .../k8s.io/sample-apiserver/Godeps/Godeps.json | 2 +- .../k8s.io/sample-cli-plugin/Godeps/Godeps.json | 2 +- .../k8s.io/sample-controller/Godeps/Godeps.json | 2 +- vendor/github.com/modern-go/reflect2/.travis.yml | 1 + vendor/github.com/modern-go/reflect2/Gopkg.toml | 2 +- vendor/github.com/modern-go/reflect2/reflect2.go | 3 +++ vendor/github.com/modern-go/reflect2/test.sh | 2 +- vendor/github.com/modern-go/reflect2/type_map.go | 16 +++++++++++++--- 18 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index e001467b23..f2cbf45b4a 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -2407,8 +2407,8 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Comment": "1.0.0-9-g05fbef0", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Comment": "v1.0.1", + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/mohae/deepcopy", diff --git a/staging/src/k8s.io/api/Godeps/Godeps.json b/staging/src/k8s.io/api/Godeps/Godeps.json index 6d345b2382..7fa2351787 100644 --- a/staging/src/k8s.io/api/Godeps/Godeps.json +++ b/staging/src/k8s.io/api/Godeps/Godeps.json @@ -44,7 +44,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/pmezard/go-difflib/difflib", diff --git a/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json b/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json index 39b9ab3656..23c32c92ba 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json @@ -572,7 +572,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/pborman/uuid", diff --git a/staging/src/k8s.io/apimachinery/Godeps/Godeps.json b/staging/src/k8s.io/apimachinery/Godeps/Godeps.json index 3a2a7473ff..1bfd0337a5 100644 --- a/staging/src/k8s.io/apimachinery/Godeps/Godeps.json +++ b/staging/src/k8s.io/apimachinery/Godeps/Godeps.json @@ -100,7 +100,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/mxk/go-flowrate/flowrate", diff --git a/staging/src/k8s.io/apiserver/Godeps/Godeps.json b/staging/src/k8s.io/apiserver/Godeps/Godeps.json index b9686508ca..813b883fe0 100644 --- a/staging/src/k8s.io/apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/apiserver/Godeps/Godeps.json @@ -544,7 +544,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/pborman/uuid", diff --git a/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json b/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json index e5edf2ebea..81d60d5a7f 100644 --- a/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json +++ b/staging/src/k8s.io/cli-runtime/Godeps/Godeps.json @@ -96,7 +96,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/peterbourgon/diskv", diff --git a/staging/src/k8s.io/client-go/Godeps/Godeps.json b/staging/src/k8s.io/client-go/Godeps/Godeps.json index 7966502990..9076b4032c 100644 --- a/staging/src/k8s.io/client-go/Godeps/Godeps.json +++ b/staging/src/k8s.io/client-go/Godeps/Godeps.json @@ -168,7 +168,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/peterbourgon/diskv", diff --git a/staging/src/k8s.io/csi-api/Godeps/Godeps.json b/staging/src/k8s.io/csi-api/Godeps/Godeps.json index f9cc4e25f1..5fba159b31 100644 --- a/staging/src/k8s.io/csi-api/Godeps/Godeps.json +++ b/staging/src/k8s.io/csi-api/Godeps/Godeps.json @@ -92,7 +92,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/peterbourgon/diskv", diff --git a/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json b/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json index dee16ad4c3..a780576d85 100644 --- a/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json +++ b/staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json @@ -260,7 +260,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/mxk/go-flowrate/flowrate", diff --git a/staging/src/k8s.io/metrics/Godeps/Godeps.json b/staging/src/k8s.io/metrics/Godeps/Godeps.json index 8a3032fd29..4dcefbeb34 100644 --- a/staging/src/k8s.io/metrics/Godeps/Godeps.json +++ b/staging/src/k8s.io/metrics/Godeps/Godeps.json @@ -84,7 +84,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/peterbourgon/diskv", diff --git a/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json b/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json index 8d406dc5b8..2f8088a05f 100644 --- a/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json @@ -252,7 +252,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/pborman/uuid", diff --git a/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json b/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json index d2e03dfa07..d2cc46c0ff 100644 --- a/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json +++ b/staging/src/k8s.io/sample-cli-plugin/Godeps/Godeps.json @@ -92,7 +92,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/peterbourgon/diskv", diff --git a/staging/src/k8s.io/sample-controller/Godeps/Godeps.json b/staging/src/k8s.io/sample-controller/Godeps/Godeps.json index 5100e609c8..afe92d652a 100644 --- a/staging/src/k8s.io/sample-controller/Godeps/Godeps.json +++ b/staging/src/k8s.io/sample-controller/Godeps/Godeps.json @@ -100,7 +100,7 @@ }, { "ImportPath": "github.com/modern-go/reflect2", - "Rev": "05fbef0ca5da472bbf96c9322b84a53edc03c9fd" + "Rev": "94122c33edd36123c84d5368cfb2b69df93a0ec8" }, { "ImportPath": "github.com/peterbourgon/diskv", diff --git a/vendor/github.com/modern-go/reflect2/.travis.yml b/vendor/github.com/modern-go/reflect2/.travis.yml index 449e67cd01..fbb43744d9 100644 --- a/vendor/github.com/modern-go/reflect2/.travis.yml +++ b/vendor/github.com/modern-go/reflect2/.travis.yml @@ -6,6 +6,7 @@ go: before_install: - go get -t -v ./... + - go get -t -v github.com/modern-go/reflect2-tests/... script: - ./test.sh diff --git a/vendor/github.com/modern-go/reflect2/Gopkg.toml b/vendor/github.com/modern-go/reflect2/Gopkg.toml index 3593fd0417..2f4f4dbdcc 100644 --- a/vendor/github.com/modern-go/reflect2/Gopkg.toml +++ b/vendor/github.com/modern-go/reflect2/Gopkg.toml @@ -24,7 +24,7 @@ # go-tests = true # unused-packages = true -ignored = ["github.com/modern-go/test","github.com/modern-go/test/must","github.com/modern-go/test/should"] +ignored = [] [[constraint]] name = "github.com/modern-go/concurrent" diff --git a/vendor/github.com/modern-go/reflect2/reflect2.go b/vendor/github.com/modern-go/reflect2/reflect2.go index 0632b71fb0..63b49c7991 100644 --- a/vendor/github.com/modern-go/reflect2/reflect2.go +++ b/vendor/github.com/modern-go/reflect2/reflect2.go @@ -150,6 +150,9 @@ func (cfg *frozenConfig) TypeOf(obj interface{}) Type { } func (cfg *frozenConfig) Type2(type1 reflect.Type) Type { + if type1 == nil { + return nil + } cacheKey := uintptr(unpackEFace(type1).data) typeObj, found := cfg.cache.Load(cacheKey) if found { diff --git a/vendor/github.com/modern-go/reflect2/test.sh b/vendor/github.com/modern-go/reflect2/test.sh index fbcef73098..3d2b9768ce 100755 --- a/vendor/github.com/modern-go/reflect2/test.sh +++ b/vendor/github.com/modern-go/reflect2/test.sh @@ -3,7 +3,7 @@ set -e echo "" > coverage.txt -for d in $(go list ./... | grep -v vendor); do +for d in $(go list github.com/modern-go/reflect2-tests/... | grep -v vendor); do go test -coverprofile=profile.out -coverpkg=github.com/modern-go/reflect2 $d if [ -f profile.out ]; then cat profile.out >> coverage.txt diff --git a/vendor/github.com/modern-go/reflect2/type_map.go b/vendor/github.com/modern-go/reflect2/type_map.go index 6d489112ff..3acfb55803 100644 --- a/vendor/github.com/modern-go/reflect2/type_map.go +++ b/vendor/github.com/modern-go/reflect2/type_map.go @@ -4,6 +4,7 @@ import ( "reflect" "runtime" "strings" + "sync" "unsafe" ) @@ -15,10 +16,17 @@ func typelinks1() [][]unsafe.Pointer //go:linkname typelinks2 reflect.typelinks func typelinks2() (sections []unsafe.Pointer, offset [][]int32) -var types = map[string]reflect.Type{} -var packages = map[string]map[string]reflect.Type{} +// initOnce guards initialization of types and packages +var initOnce sync.Once + +var types map[string]reflect.Type +var packages map[string]map[string]reflect.Type + +// discoverTypes initializes types and packages +func discoverTypes() { + types = make(map[string]reflect.Type) + packages = make(map[string]map[string]reflect.Type) -func init() { ver := runtime.Version() if ver == "go1.5" || strings.HasPrefix(ver, "go1.5.") { loadGo15Types() @@ -90,11 +98,13 @@ type emptyInterface struct { // TypeByName return the type by its name, just like Class.forName in java func TypeByName(typeName string) Type { + initOnce.Do(discoverTypes) return Type2(types[typeName]) } // TypeByPackageName return the type by its package and name func TypeByPackageName(pkgPath string, name string) Type { + initOnce.Do(discoverTypes) pkgTypes := packages[pkgPath] if pkgTypes == nil { return nil