Skip to content

perf: optimize countingWaitGroup for faster Count() operations #9162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

analytically
Copy link
Contributor

@analytically analytically commented Mar 25, 2025

Improve performance of the countingWaitGroup implementation while
maintaining the original behavior:

  • Use atomic.Int64 for the counter to enable lock-free Count() reads
  • Keep mutex synchronization for Add() and Done() to ensure atomicity
    between WaitGroup operations and counter updates
  • Significantly reduce contention when multiple goroutines read the count
    while operations are in progress

This change improves performance when the beacon rebalancing logic
frequently checks the Count() value.

@analytically analytically requested a review from a team as a code owner March 25, 2025 21:23
Improve performance of the countingWaitGroup implementation while
maintaining the original behavior:

- Use atomic.Int64 for the counter to enable lock-free Count() reads
- Keep mutex synchronization for Add() and Done() to ensure atomicity
  between WaitGroup operations and counter updates
- Significantly reduce contention when multiple goroutines read the count
  while operations are in progress

This change improves performance when the beacon rebalancing logic
frequently checks the Count() value.

Signed-off-by: Mathias Bogaert <[email protected]>
@analytically analytically changed the title refactor: optimize countingWaitGroup with atomic.Int64 perf: optimize countingWaitGroup for faster Count() operations Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

1 participant