Skip to content

Commit

Permalink
perf: avoid executing the loop when the log level is not debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ev1lQuark committed Jun 3, 2023
1 parent 0d795bb commit a3b32b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
14 changes: 10 additions & 4 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ func (cc *ConsumerConfig) Init(rc *RootConfig) error {
return nil
}

consumerNames := make([]string, 0, len(cc.References))
for k := range cc.References {
consumerNames = append(consumerNames, k)
buildDebugMsg := func() string {
if len(cc.References) == 0 {
return "empty"
}
consumerNames := make([]string, 0, len(cc.References))
for k := range cc.References {
consumerNames = append(consumerNames, k)
}
return strings.Join(consumerNames, ", ")
}
logger.Debugf("Registered consumer clients are %v", strings.Join(consumerNames, ", "))
logger.Debugf("Registered consumer clients are %v", buildDebugMsg())

cc.RegistryIDs = translateIds(cc.RegistryIDs)
if len(cc.RegistryIDs) <= 0 {
Expand Down
15 changes: 10 additions & 5 deletions config/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
if c == nil {
return nil
}

providerNames := make([]string, 0, len(c.Services))
for k := range c.Services {
providerNames = append(providerNames, k)
buildDebugMsg := func() string {
if len(c.Services) == 0 {
return "empty"
}
providerNames := make([]string, 0, len(c.Services))
for k := range c.Services {
providerNames = append(providerNames, k)
}
return strings.Join(providerNames, ", ")
}
logger.Debugf("Registered provider services are %v", strings.Join(providerNames, ", "))
logger.Debugf("Registered provider services are %v", buildDebugMsg())

c.RegistryIDs = translateIds(c.RegistryIDs)
if len(c.RegistryIDs) <= 0 {
Expand Down

0 comments on commit a3b32b2

Please sign in to comment.