Skip to content

perf: avoid unnecessary copy operation #3376

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 5 commits into
base: master
Choose a base branch
from

Conversation

fukua95
Copy link
Contributor

@fukua95 fukua95 commented May 11, 2025

  • reduce unnecessary copy operations in file ring.go
  • remove redundant hash operation in file ring.go

In struct Ring, the size of shards can be up to 100 (#2190 (comment)), in this case, a copy operation is called for each heartbeat, and approximately 3.1 KB data are copied. This is a waste of CPU resources. So avoiding copy operations yields benefits.

The pr #2931 reported a race here, but ​​there actually isn't one. Because every time we get the slice c.shards.list, we don't change slice itself, we only use c.shards.list[i].Client which is concurrency-safe.

@fukua95 fukua95 changed the title optime: reduce unnecessary copy operations optimize: reduce unnecessary copy operations May 11, 2025
@fukua95 fukua95 changed the title optimize: reduce unnecessary copy operations perf: avoid unnecessary copy operation May 14, 2025
@fukua95 fukua95 force-pushed the optimize/reduce-copy branch from 1ad81f8 to 8cd300f Compare May 15, 2025 13:11
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