-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix manifest reader inefficiency (#160)
For some reason this only has popped up when trying to sync opa constraints but there are two major inefficiencies w/ manifest reader right now: * has to go through RESTMapper to check namespacing (this can sometimes result in a network call, so caching is a meaningful optimization) * Apparently it doubles the array on each cycle because it calls read on its own result list. Think we've only used small sets of files for raw resources prior so never became an issue, but it's definitely an issue at large file sets (as you suddenly have a result of like 48k)
- Loading branch information
1 parent
aee91d2
commit f5aaabe
Showing
5 changed files
with
46 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package template | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
var ( | ||
namespacedCache = &gvkCache{cache: map[schema.GroupVersionKind]bool{}} | ||
) | ||
|
||
type gvkCache struct { | ||
cache map[schema.GroupVersionKind]bool | ||
} | ||
|
||
func (c *gvkCache) Store(gvk schema.GroupVersionKind, namespaced bool) { | ||
c.cache[gvk] = namespaced | ||
} | ||
|
||
func (c *gvkCache) Namespaced(gvk schema.GroupVersionKind) bool { | ||
val, ok := c.cache[gvk] | ||
return ok && val | ||
} | ||
|
||
func (c *gvkCache) Present(gvk schema.GroupVersionKind) bool { | ||
_, ok := c.cache[gvk] | ||
return ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters