Skip to content

Commit 63cb583

Browse files
authored
Merge pull request kubernetes#129628 from 249043822/br004
remove duplicate getAttrsFunc calls to reduce temporary memory allocations
2 parents 6d24d3b + 479ff5a commit 63cb583

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/fields"
3131
"k8s.io/apimachinery/pkg/labels"
32-
"k8s.io/apimachinery/pkg/runtime"
3332
"k8s.io/apimachinery/pkg/runtime/schema"
3433
"k8s.io/apimachinery/pkg/util/wait"
3534
"k8s.io/apimachinery/pkg/watch"
@@ -288,10 +287,6 @@ func TestCacheWatcherStoppedOnDestroy(t *testing.T) {
288287
}
289288

290289
func TestResourceVersionAfterInitEvents(t *testing.T) {
291-
getAttrsFunc := func(obj runtime.Object) (labels.Set, fields.Set, error) {
292-
return nil, nil, nil
293-
}
294-
295290
const numObjects = 10
296291
store := cache.NewIndexer(storeElementKey, storeElementIndexers(nil))
297292

@@ -300,7 +295,7 @@ func TestResourceVersionAfterInitEvents(t *testing.T) {
300295
store.Add(elem)
301296
}
302297

303-
wci, err := newCacheIntervalFromStore(numObjects, store, getAttrsFunc, "", false)
298+
wci, err := newCacheIntervalFromStore(numObjects, store, "", false)
304299
if err != nil {
305300
t.Fatal(err)
306301
}

staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ func (w *watchCache) getAllEventsSinceLocked(resourceVersion uint64, key string,
752752
// that covers the entire storage state.
753753
// This function assumes to be called under the watchCache lock.
754754
func (w *watchCache) getIntervalFromStoreLocked(key string, matchesSingle bool) (*watchCacheInterval, error) {
755-
ci, err := newCacheIntervalFromStore(w.resourceVersion, w.store, w.getAttrsFunc, key, matchesSingle)
755+
ci, err := newCacheIntervalFromStore(w.resourceVersion, w.store, key, matchesSingle)
756756
if err != nil {
757757
return nil, err
758758
}

staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache_interval.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
"sort"
2222
"sync"
2323

24-
"k8s.io/apimachinery/pkg/fields"
25-
"k8s.io/apimachinery/pkg/labels"
26-
"k8s.io/apimachinery/pkg/runtime"
2724
"k8s.io/apimachinery/pkg/watch"
2825
)
2926

@@ -106,7 +103,6 @@ type watchCacheInterval struct {
106103
initialEventsEndBookmark *watchCacheEvent
107104
}
108105

109-
type attrFunc func(runtime.Object) (labels.Set, fields.Set, error)
110106
type indexerFunc func(int) *watchCacheEvent
111107
type indexValidator func(int) bool
112108

@@ -140,10 +136,9 @@ func (s sortableWatchCacheEvents) Swap(i, j int) {
140136
// returned by Next() need to be events from a List() done on the underlying store of
141137
// the watch cache.
142138
// The items returned in the interval will be sorted by Key.
143-
func newCacheIntervalFromStore(resourceVersion uint64, store storeIndexer, getAttrsFunc attrFunc, key string, matchesSingle bool) (*watchCacheInterval, error) {
139+
func newCacheIntervalFromStore(resourceVersion uint64, store storeIndexer, key string, matchesSingle bool) (*watchCacheInterval, error) {
144140
buffer := &watchCacheIntervalBuffer{}
145141
var allItems []interface{}
146-
147142
if matchesSingle {
148143
item, exists, err := store.GetByKey(key)
149144
if err != nil {
@@ -162,15 +157,11 @@ func newCacheIntervalFromStore(resourceVersion uint64, store storeIndexer, getAt
162157
if !ok {
163158
return nil, fmt.Errorf("not a storeElement: %v", elem)
164159
}
165-
objLabels, objFields, err := getAttrsFunc(elem.Object)
166-
if err != nil {
167-
return nil, err
168-
}
169160
buffer.buffer[i] = &watchCacheEvent{
170161
Type: watch.Added,
171162
Object: elem.Object,
172-
ObjLabels: objLabels,
173-
ObjFields: objFields,
163+
ObjLabels: elem.Labels,
164+
ObjFields: elem.Fields,
174165
Key: elem.Key,
175166
ResourceVersion: resourceVersion,
176167
}

staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache_interval_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func TestCacheIntervalNextFromStore(t *testing.T) {
392392
store.Add(elem)
393393
}
394394

395-
wci, err := newCacheIntervalFromStore(rv, store, getAttrsFunc, "", false)
395+
wci, err := newCacheIntervalFromStore(rv, store, "", false)
396396
if err != nil {
397397
t.Fatal(err)
398398
}

0 commit comments

Comments
 (0)