Skip to content

Conversation

@ZMbiubiubiu
Copy link

1.Remove the duplicate code 'b.m = make(map[uint64]uint64)'
2.Because of the protection of the lock, you can operate without using atoms

@ZMbiubiubiu
Copy link
Author

@valyala I hope you can take a lokk at it sometime

@f41gh7 f41gh7 requested review from Copilot and f41gh7 July 27, 2025 12:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes duplicate initialization code and simplifies atomic operations in the bucket Reset method. The changes eliminate redundant map initialization and replace atomic store operations with direct assignments under lock protection.

  • Removes duplicate b.m = make(map[uint64]uint64) initialization in bucket Init method
  • Replaces atomic store operations with direct assignments in Reset method since they occur under mutex protection

atomic.StoreUint64(&b.misses, 0)
atomic.StoreUint64(&b.collisions, 0)
atomic.StoreUint64(&b.corruptions, 0)
b.getCalls = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.getCalls may cause race conditions if other goroutines read this field concurrently without holding the mutex. If getCalls is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Copilot uses AI. Check for mistakes.
atomic.StoreUint64(&b.collisions, 0)
atomic.StoreUint64(&b.corruptions, 0)
b.getCalls = 0
b.setCalls = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.setCalls may cause race conditions if other goroutines read this field concurrently without holding the mutex. If setCalls is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Copilot uses AI. Check for mistakes.
atomic.StoreUint64(&b.corruptions, 0)
b.getCalls = 0
b.setCalls = 0
b.misses = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.misses may cause race conditions if other goroutines read this field concurrently without holding the mutex. If misses is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Copilot uses AI. Check for mistakes.
b.getCalls = 0
b.setCalls = 0
b.misses = 0
b.collisions = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.collisions may cause race conditions if other goroutines read this field concurrently without holding the mutex. If collisions is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Suggested change
b.collisions = 0
atomic.StoreUint64(&b.collisions, 0)

Copilot uses AI. Check for mistakes.
b.setCalls = 0
b.misses = 0
b.collisions = 0
b.corruptions = 0
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct assignment to b.corruptions may cause race conditions if other goroutines read this field concurrently without holding the mutex. If corruptions is accessed outside the mutex elsewhere in the code, atomic operations should be retained.

Suggested change
b.corruptions = 0
atomic.StoreUint64(&b.corruptions, 0)

Copilot uses AI. Check for mistakes.
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.

1 participant