Cache GoogleProdCredsExist() to save ~800ms during builds.
During a m nothing call; GoogleProdCredsExist check is called 3 times.
Each call is ~400ms so caching during the run will save ~800ms.
Test: time m nothing
Change-Id: I8a92c8fa48b22c7fb56be0f3c9cb5bf8787da6a9
diff --git a/ui/build/config.go b/ui/build/config.go
index b5ee440..d9103ba 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -45,7 +45,8 @@
)
var (
- rbeRandPrefix int
+ rbeRandPrefix int
+ googleProdCredsExistCache bool
)
func init() {
@@ -1347,9 +1348,13 @@
// GoogleProdCredsExist determine whether credentials exist on the
// Googler machine to use remote execution.
func (c *configImpl) GoogleProdCredsExist() bool {
+ if googleProdCredsExistCache {
+ return googleProdCredsExistCache
+ }
if _, err := exec.Command("/usr/bin/prodcertstatus", "--simple_output", "--nocheck_loas").Output(); err != nil {
return false
}
+ googleProdCredsExistCache = true
return true
}