Skip to content

Conversation

ghrushneshr25
Copy link
Contributor

Summary

This PR improves the performance and clarity of the Each method in ServerList by adding an early return when there are no server addresses (ss.addrs) to iterate over.

Changes

  • Added a len(ss.addrs) == 0 check at the beginning of Each() to return ErrNoServers immediately, avoiding unnecessary locking and iteration.
  • Improves efficiency, especially in scenarios where Each() is frequently called (e.g., Client.Ping()).
  • Provides clearer behaviour and quicker feedback when the server list is empty.

Benefits

  • Reduces lock contention.
  • Improves Ping() response time when no servers are available.
  • Fails fast with a meaningful error.

@ghrushneshr25
Copy link
Contributor Author

@bradfitz @dormando this PR can solve the #179 issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants